adding checkbox to a Cgridview with condition

Hi

I want to add checkbox to one of the columns in the grid. The column displays a field from a table which i want as checkbox. The checkbox should be checked when the field value is 1 or else unchecked. Also i want to make this checkbox disabled.

I tried the following code but getting errors:

‘columns’=>array(

	'Rule_List_id',


	'rule_name',


	'rule_desc',


	array(


		'name'=>'rule_isenabled',   


		'value'=>CHtml::checkBox('selectedItems', false, array('value'=>$model->rule_isenabled)),

Please help me…

you can use CChekBoxColumn:

http://www.yiiframework.com/doc/api/1.1/CCheckBoxColumn/

and you can call like this in Grid Column:




array(

  'class'=>'CChekBoxColumn',

  'header'=>'CHEK',

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

)



Thanks Hermans, i could see the checkbox but it is unchecked throughout.I want it to be checked is rule_isenabled field value is 1. Could you help me? Is there anyway i can set the condition for it?

what value in rule_isenabled ?

i tried example ‘a’ is true / 1.




'value'=>'$data->rule_isenabled == 'a' ? 1 : 0',



rule_isenabled contains 1 or 0

"value" is used to give a value to the checkbox field… to set the "checked" state of the CCheckBoxColumn use the checked property - http://www.yiiframework.com/doc/api/1.1/CCheckBoxColumn#checked-detail

meant to be like this:




'checked'=>'$data->rule_isenabled',



Thank you very much it worked!!!! :lol:

array(

'class'=>'CCheckBoxColumn',


'header'=>'Enabled',


'checked'=>'$data->rule_isenabled',


),

yes, I am also grateful to @mdomba.