CCheckBoxColumn and complex datacolumns


I have a cgridview based on a model.

In the model I’m using complex data columns, i.e. I get a new value as a function of the column.

How can I generate a checkbox column for the generated column? Well, I can generate the column of checkboxes, but I wonder if I can make some of these checkboxes to be checked based on its value.

For example with this code, I can generate the column of checkboxes using values generated by “calculate_new_value”, but I don’t know how to have checkboxes checked.

$this->widget('zii.widgets.grid.CGridView', array(







			'selectableRows' => 2,


			'name' => 'stores[]',


			'value'=>array($model, 'calculate_new_value'), 			


I hope I’m making sense.

Thanks a lot.

Check This , might be helpful ;)

Thanks for the link, but I didn’t see a way to have checkboxes checked depending on the column value.

The closest think I think I could do, is to obtain somwhere an array of the rows that would be checked and

then do something like they suggest




               'checked'=>'in_array($data->id, $array_of_ids_with_condition)'


But I still wonder if there would be a simpler way of generating checked checkboxes based on its value. I can generate a column of 0’s and 1’s and I’d love to be able to use that value to determine the checkboxes status.

Is there really no easy way to prepopulate a checkbox column?

It might work if you use the $data variable, and a model function?:


Thank you!

This is the an answer to what I was looking for, and it is what I’m gonna be using.