Search code examples
phpcheckboxyiicgridview

Show Checkbox was checked in CGridView Yii 1.1


I have a CGridView with Checkbox column like this:

array(
      'name' => 'updated',
      'id' => 'selectedIds',
      'value' => '$data->id',
      'class' => 'CCheckBoxColumn',
      'checkBoxHtmlOptions' => [
           'class' => 'checkbox-ajax'
      ]
),

and I have a field updated DB with 0 if not update and 1 if updated.

Now I want to check the row in CGridView if field updated = 1, this row will be bold or highlight this.

Any solutions for this case?


Solution

  • You need to add one more parameter in field's array. Here i added one more parameter in array i.e. checked. See below solution.

    array(
                'name' => 'updated',
                'header' => 'updated',
                'id' => 'selectedIds',
                'value' => '$data->id',
                'class' => 'CCheckBoxColumn',
                'checked' => function($data){ return ($data->updated == 1) ? true:false;},
                'checkBoxHtmlOptions' => [
                    'class' => 'checkbox-ajax'
                ]
            ),