Update selected checkbox


(Kazi Neel) #1

I have checkbox per row and want to update selected checkbox. Controller action is not working, can anyone help me.

Here is my view file

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘dataProvider’=>$dataProvider,

‘columns’=>array(

    'id',


    array(


    'name'=&gt;'Action',             'value'=&gt;'CHtml::checkBox(&quot;cid[]&quot;,null,array(&quot;value&quot;=&gt;&#036;data-&gt;id,&quot;id&quot;=&gt;&quot;cid_&quot;.&#036;data-&gt;id))',


    'type'=&gt;'raw',


    'htmlOptions'=&gt;array('width'=&gt;5),


    //'visible'=&gt;false,


    ),


    'name',


    'email',

),

)); ?>


(Nemoneel) #2

I am facing same problem. If anyone help that will be great.


(Vamphouse) #3

please, specify what do you mean, saying "update selected checkbox" - you need check/uncheck checkbox and you know it id?


(Jon) #4

There is a checkbox column type already existing:

CCheckBoxColumn

Theoretically this should fix your issue if implemented :slight_smile:

Example usage in another forum post:

http://www.yiiframework.com/forum/index.php?/topic/7380-cgridview-selectablerows-quirk/


(Nemoneel) #5

Suppose I have 100 data and select 5 data using checkbox to assign to my User_id. Is that possible.

Here is my view file

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘dataProvider’=>$dataProvider,

‘columns’=>array(

‘id’,

array(

‘name’=>‘Action’,

‘value’=>‘CHtml::checkBox(“cid[]”,null,array(“update”,“value”=>$data->id,“id”=>“cid_”.$data->id))’,

,

‘type’=>‘raw’,

‘htmlOptions’=>array(‘width’=>5),

//‘visible’=>false,

),

‘item1’,

‘item2’,

),

)); ?>

I really appreciate if any one help me about controller action file.


(Nemoneel) #6

Can you help me with example? I really need that to implement my website.


(Jon) #7

Please refer to my previous post:


(Nemoneel) #8

Can you help me with example code?


(Jon) #9

I’ve not used it yet myself, but there is example code in the post that I linked to in my prior posts.


(Nemoneel) #10

Can you tell me how to create button or link for delete/update on the top?

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

    'dataProvider'=&gt;&#036;dataProvider,


    'showTableOnEmpty'=&gt;false,


    'selectableRows'=&gt;2,


    'emptyText'=&gt;'Nowt to see.',


    'columns'=&gt;array(


            array(


                    'class'=&gt;'CCheckBoxColumn',


                    'name'=&gt;'delete',


                    'value'=&gt;'&#036;data-&gt;id',


                    'id'=&gt;'delete'


            ),


           'name',


	'loginName',


	'password',


	'email',


    ),

)); ?>