Yii Framework Forum: Can i add a checkbox on per row in the CGridView? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Can i add a checkbox on per row in the CGridView? Rate Topic: -----

#1 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 06 February 2010 - 03:02 AM

i want add a checkbox on per row,can I?
0

#2 User is offline   StErMi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 259
  • Joined: 30-March 09

Posted 06 February 2010 - 05:37 AM

me too, and add javascript action when checked!
0

#3 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 06 February 2010 - 05:58 AM

I solved. like this:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
	'id',
	array(
	'name'=>'',		'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->id,"id"=>"cid_".$data->id))',
	'type'=>'raw',
	'htmlOptions'=>array('width'=>5),
	//'visible'=>false,
	),
	'name',
	'email',
),
)); ?>

if you want check the checkbox is checked or not,use this javascript before you submit:
var item = $("form input:checkbox:checked");
if(item.length==0) {
alert('Plese select checkbox!');
return false;
}

0

#4 User is offline   StErMi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 259
  • Joined: 30-March 09

Posted 06 February 2010 - 08:44 AM

thank you very much :)
0

#5 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 08 March 2010 - 08:16 AM

View Postholala, on 06 February 2010 - 05:58 AM, said:

I solved. like this:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
	'id',
	array(
	'name'=>'',		'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->id,"id"=>"cid_".$data->id))',
	'type'=>'raw',
	'htmlOptions'=>array('width'=>5),
	//'visible'=>false,
	),
	'name',
	'email',
),
)); ?>

if you want check the checkbox is checked or not,use this javascript before you submit:
var item = $("form input:checkbox:checked");
if(item.length==0) {
alert('Plese select checkbox!');
return false;
}



Hi,
I am newly using YII and need the same thing what you did. Can you help me how to add delete/update button or link on the top and also need the action for delete and update? It will really help me alot
THank\
0

#6 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 08 March 2010 - 08:48 AM

View Postnemo, on 08 March 2010 - 08:16 AM, said:

Hi,
I am newly using YII and need the same thing what you did. Can you help me how to add delete/update button or link on the top and also need the action for delete and update? It will really help me alot
THank\


Can anyone help me plz? I really appreciate if anyone help me about my problem.

:(
PLZ help me
0

#7 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 08 March 2010 - 12:49 PM

:(
Plz Help me.
0

#8 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

Posted 19 March 2010 - 02:03 PM

View Postholala, on 06 February 2010 - 05:58 AM, said:

I solved. like this:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
	'id',
	array(
	'name'=>'',		'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->id,"id"=>"cid_".$data->id))',
	'type'=>'raw',
	'htmlOptions'=>array('width'=>5),
	//'visible'=>false,
	),
	'name',
	'email',
),
)); ?>

if you want check the checkbox is checked or not,use this javascript before you submit:
var item = $("form input:checkbox:checked");
if(item.length==0) {
alert('Plese select checkbox!');
return false;
}



Can you post the action controller? I m doing the same thing.

THis action controller is not working

public function actionMultiupdate()
{
$this->_model=TnRecords::model()->updateAll(array("User_id"=>0),"id IN (" .implode(",",$_POST["cid"]).")");
$this->redirect(array('admin'));
}
I got this error

Description
implode() [<a href='function.implode'>function.implode</a>]:
Invalid arguments passed

Have any idea?
0

#9 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 10 July 2010 - 12:37 PM

There is a CCheckBox class that works too..

It only seems to have some css selection error with me :)
http://www.yiiframew...CCheckBoxColumn

Example..
<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'post-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
    'selectableRows' => 2,
	'columns'=>array(
        array(
			'class'=>'CCheckBoxColumn',            
		),
        array(
            'name'  => 'id',
            'htmlOptions' => array('style'=>'width:30px;'),
        ),
        array(
            'name'=>'status',
            'value'=> '$data->getStatusName($data->status);',            
        ),
		'title',
        array(            
            'name'=>'created',
            'value'=> 'Yii::app()->getDateFormatter()->format("dd-MM-yyyy",$data->created);',
        ),
		array(
			'class'=>'CButtonColumn',
		)        
	),
)); ?>

0

#10 User is offline   newscloud 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 02-April 13

Posted 17 January 2014 - 03:39 AM

Here's an example of CGridView with CCheckboxColumn, Select All and an Action Button:
http://jeffreifman.com/yii/cgridview/
1

#11 User is offline   justinthomasonline 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-July 12
  • Location:india,kerala,kottayam

Posted 21 August 2014 - 05:04 AM

<?php

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'a-grid-id',
'dataProvider' => $model,
'ajaxUpdate' => true, //false if you want to reload aentire page (useful if sorting has an effect to other widgets)
'filter' => null, //if not exist search filters
'columns' => array(
array(
'name'=>'Check',
'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data[\'Eid\']))',
'type'=>'raw',
'htmlOptions'=>array('width'=>5),
//'visible'=>false,
),

'Eid',
'AName',
'prdcName',
'NextContDate',
'NextAction',
array(
'name'=>'Mail',
'type'=>'raw',
'value'=>function($data)
{
if ($data['Email']!="")
{
CHtml::mailto($email=$data['Email']);
}else
{
echo "Email not specified";
}
},

),


),
)); ?>
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users