How to add a checkbox column at first column of datagrid / CGridView

Yii have very pretty solution for this.

We need

  1. array(
  2.  ‘class’ => ‘CCheckBoxColumn’,
  3. ‘value’=>‘Your_Value’,
  4. ‘selectableRows’ => ’50′,
  5. ),

Above array need to use inside CGridView

Example:

  1. $this->widget(‘zii.widgets.grid.CGridView’, array(
  2.                         ‘id’ => ‘customers-grid’,
  3.                         ‘dataProvider’ => $dataProvider,
  4.                         ‘itemsCssClass’ => ‘table table-striped’,
  5.                         ‘columns’ => array(
  6.                             array(
  7.                                 ‘class’ => ‘CCheckBoxColumn’,
  8.                                 ‘value’=>‘Your_Value’,
  9.                                 ‘selectableRows’ => ’50′,
  10.                             ),
  11.                             array(
  12.                                 ‘name’ => ‘user_login_id_fk’,
  13.                                 ‘header’ => ‘First Name’,
  14.                                 ‘value’ => ‘$data->userLoginIdFk->customerProfiles[0]->first_name’,
  15.                             ),
  16.                             array(
  17.                                 ‘name’ => ‘user_login_id_fk’,
  18.                                 ‘header’ => ‘Last Name’,
  19.                                 ‘value’ => ‘$data->userLoginIdFk->customerProfiles[0]->last_name’,
  20.                             ),
  21.                             array(
  22.                                 ‘name’ => ‘user_login_id_fk’,
  23.                                 ‘header’ => ‘Email’,
  24.                                 ‘value’ => ‘$data->userLoginIdFk->email’,
  25.                             ),
  26.                             array(
  27.                                 ‘name’ => ‘user_login_id_fk’,
  28.                                 ‘header’ => ‘Country’,
  29.                                 ‘value’ => ‘Country::model()->getCountryName($data->userLoginIdFk->customerProfiles[0]->country_code)’,
  30.                             ),
  31.                             array(
  32.                                 ‘name’ => ‘user_login_id_fk’,
  33.                                 ‘header’ => ‘Category’,
  34.                                 ‘value’ => ,
  35.                             ),
  36.                             array(
  37.                                 ‘name’ => ‘user_login_id_fk’,
  38.                                 ‘header’ => ‘Rating’,
  39.                                 ‘value’ => ‘$data->userLoginIdFk->customerProfiles[0]->rating’,
  40.                             ),
  41.                             array(
  42.                                 ‘class’ => ‘CButtonColumn’,
  43.                                 ‘template’ => ‘{view}’,
  44.                                 ‘buttons’ => array(
  45.                                     ‘view’ => array(
  46.                                         ‘label’ => ‘View’,
  47.                                         ‘url’ => ‘Yii::app()->createUrl(“//member/customerprofile/view/”,array(“id”=>$data->user_login_id_fk,”with”=>”userloginid”))’,
  48.                                         ‘imageUrl’ => Yii::app()->theme->baseUrl . ‘/assets/icon/view.png’,
  49.                                     ),
  50.                                     ‘update’ => array(
  51.                                         ‘label’ => ‘Update’,
  52.                                         ‘imageUrl’ => Yii::app()->theme->baseUrl . ‘/assets/icon/edit.png’,
  53.                                     ),
  54.                                 ),
  55.                             ),
  56.                         ),
  57.                     ));

I think u people enjoy it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>