tad
(Truptidesai09)
July 26, 2011, 4:30am
1
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…
h3rm
July 26, 2011, 5:43am
2
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',
)
tad
(Truptidesai09)
July 26, 2011, 6:37am
3
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?
h3rm
July 26, 2011, 6:43am
4
what value in rule_isenabled ?
i tried example ‘a’ is true / 1.
'value'=>'$data->rule_isenabled == 'a' ? 1 : 0',
tad
(Truptidesai09)
July 26, 2011, 6:57am
5
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
mdomba
(Maurizio Domba Cerin)
July 26, 2011, 7:01am
6
"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
h3rm
July 26, 2011, 7:19am
7
meant to be like this:
'checked'=>'$data->rule_isenabled',
tad
(Truptidesai09)
July 26, 2011, 8:05am
8
Thank you very much it worked!!!!
array(
'class'=>'CCheckBoxColumn',
'header'=>'Enabled',
'checked'=>'$data->rule_isenabled',
),
h3rm
July 26, 2011, 8:07am
9
yes, I am also grateful to @mdomba .