Yii 1.1: CGridView customized CCheckBoxColumn

6 followers

Hi friends,

Here two things we are going to do

1) How to add dynamic tag in header for styling header layout and

2) How to add dynamic tag in column for styling column layout

3) How to add dynamic tag after filter result.

a) First point can be achieved by below code (Its default attribute from YII)

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'programm-grid',
    'dataProvider'=>$model->search(),
    //'rowCssClassExpression'=>'$this->dataProvider->data[$row]->pgm_id',
    'filter'=>$model,
    'columns'=>array(
        array(
            'header'=>'html',
            'id'=>'state_id',
            'class'=>'CCheckBoxColumn',
            'selectableRows' => '50',
            'selectableRows'=>2,
            'value'=>'$data->pgm_web_status',
            'headerTemplate'=>'<label>{item}<span></span></label>',
            'htmlOptions'=>array('style'=>'width: 20px','class'=>'chandran'),
        ),
          ),
));

b) Second point can be achieved by below jquery code (This is a trick from me :) )

Yii::app()->clientScript->registerScript('search', "
 
$('[id^=state_id_]').wrap('<label class=list></label>');
$( '<span></span>' ).insertAfter( '[id^=state_id_]');       
 
");

c) Third point can be achieved by below jquery code in cgridveiw (Trick here goes)

$this->widget('zii.widgets.grid.CGridView', array(
    'afterAjaxUpdate'=>'function(id, data){
        $("[id^=state_id_]").wrap("<label class=list></label>");
        $("<span></span>").insertAfter("[id^=state_id_]");      
    }',
        'id'=>'programm-grid',
));

I hope it will help some one else who trying to modify layout for CCheckBoxColumn column Have a fun cheers :)

Total 2 comments

#17012 report it
chandran at 2014/04/24 02:50am
Solution can be

you should check what this $model->search() method returns. I think you dont have value or its returning null

#17011 report it
Fatimah Al-Husain at 2014/04/24 02:24am
got an error

The "dataProvider" property cannot be empty. can u help me plz

Leave a comment

Please to leave your comment.

Write new article