Can i add a checkbox on per row in the CGridView?

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

me too, and add javascript action when checked!

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;

}



thank you very much :)

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

:(

Plz Help me.

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

THis action controller is not working

public function actionMultiupdate()

{


	&#036;this-&gt;_model=TnRecords::model()-&gt;updateAll(array(&quot;User_id&quot;=&gt;0),&quot;id IN (&quot; .implode(&quot;,&quot;,&#036;_POST[&quot;cid&quot;]).&quot;)&quot;);


	&#036;this-&gt;redirect(array('admin'));


}

I got this error

Description

implode() [<a href=‘function.implode’>function.implode</a>]:

Invalid arguments passed

Have any idea?

There is a CCheckBox class that works too…

It only seems to have some css selection error with me :)

http://www.yiiframework.com/doc/api/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',

		)        

	),

)); ?>



Here’s an example of CGridView with CCheckboxColumn, Select All and an Action Button:

http://jeffreifman.com/yii/cgridview/

<?php

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

'id' =&gt; 'a-grid-id',


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


'ajaxUpdate' =&gt; true, //false if you want to reload aentire page (useful if sorting has an effect to other widgets)


'filter' =&gt; null, //if not exist search filters


'columns' =&gt; array(


    array(


    'name'=&gt;'Check',


    'value'=&gt;'CHtml::checkBox(&quot;cid[]&quot;,null,array(&quot;value&quot;=&gt;&#036;data[&#092;'Eid&#092;']))',


    'type'=&gt;'raw',


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


    //'visible'=&gt;false,


      ),


   


   'Eid',


   'AName',


    'prdcName',


    'NextContDate',


    'NextAction',


      array(


        'name'=&gt;'Mail',


        'type'=&gt;'raw',


        'value'=&gt;function(&#036;data)


            {


                if (&#036;data['Email']&#33;=&quot;&quot;)


                    {


                        CHtml::mailto(&#036;email=&#036;data['Email']);


                    }else 


                    {


                        echo &quot;Email not specified&quot;;


                    }


            },


        


          ),  


    





),

)); ?>