CGridView customized CCheckBoxColumn

3 0
6
Viewed: 24 040 times
Version: Unknown (update)
Category: Tips
Written by: chandran chandran
Updated by: CeBe CeBe
Created: Feb 18, 2014
Updated: 12 years ago

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

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

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_]');		
		
");

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