[Solved] Problem With Checkbox In Gridview

I just want to print a checkbox and have it be checked/unchecked depending on some database value. The problem I face is that the CCheckBoxColumn class does funny things.

I found this, but it didn’t help:

The reason being that the $headerCheckBoxVisible variable/property/whatever doesn’t exist in the CheckBoxColumn class. I couldn’t even find it in the source code (https://github.com/yiisoft/yii/blob/1.1.14/framework/zii/widgets/grid/CCheckBoxColumn.php).

If I do the following:

The header (“Activar” in this case) is removed and replaced with a checkbox to select/deselect all available checkboxes. If I remove the ‘selectableRows’ property, the header “Activar” is available but only one checkbox can be selected at the same time.

This is a problem. My user won’t know what that column is supposed to do if the text is removed, but if I have the text in the header only one checkbox will be used and it will confuse the user.

I just want to print the checkboxes with preselected values of check/uncheck, some htmlOptions, and the client side code will do the rest.

I tried doing it with CDataColumn and just print the checkbox HTML into the value property, like the following:

But the characters are escaped and I just get text instead of the checkbox input.

Would the headerTemplate help you? - http://www.yiiframework.com/doc/api/1.1/CCheckBoxColumn#headerTemplate-detail

Yes, that worked. Thank you. I’m an idiot and didn’t see that property in the list.

Just adding a

makes it work as expected with the selectableRows property set as 2.