adding checkbox to a Cgridview with condition


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:







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

Please help me…

you can use CChekBoxColumn:

and you can call like this in Grid Column:






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 -

meant to be like this:


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






yes, I am also grateful to @mdomba.