Select Multiple Rows From The Gridview With A Single Checkbox Click

Hi,

 Below is a sample gridview.

a) How to place a checkbox at the header and select multiple rows from the grid to delete the selected ones?

b)While uncommetning the lines to place checkbox,showing error as ‘Property “CDataColumn.0” is not defined’. Any help is appreciated.


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

	'dataProvider' => $MyModel->search(),


	'filter' => $MyModel,


	'selectableRows' => 2,	


	'columns' => array(


			/* array(


					array(


							'id'=>'autoId',


				            'class'=>'CCheckBoxColumn',


				            'selectableRows' => '50', 


				            ),


			


			), */


						array(


								'name' => 'DepID',


								'type' => 'raw',


								'value' => 'CHtml::encode($data->DepID)'


						      ),


						


						array(


								'name' => 'DepartmentName',


								'type' => 'raw',


								'value' => 'CHtml::encode($data->DepartmentName)',


								


							 )


						


						


		),

));

Hi,

you should use code snippet for your code in this forum, it’s more viewable.

You can try this for the checkbox:




array(

   'header'=>'Select',

   'value'=>'$data->DepID',

   'class'=>'CCheckBoxColumn',

),



You must use the value to key table, it will be use as a param for the delete function.

For an ajax link and the function, you can see at http://yiiexemples.blogspot.fr/2011/06/cgridview-effacement-de-lignes-par-lot.html. It’s in french, but it’s not very difficult to understand what code do.