Search code examples
phpyiiyii-components

Adding an expression in htmlOptions of CGridView


I'm trying to set the htmlOptions using a value from the array used as DataProvider of the CGridView component (it's a CArrayDataProvider). In it there is a flag that will be either 0 or 1 (0 for font-weight: normal and 1 for bold)

'htmlOptions'=>array('style'=>'$data["flag"] == 1 ? font-weight: bold; : font-weight: normal;'),

It didn't work, so I tried to set the style directly in the DataProvider (returning font-weight: bold; or font-weight: normal;):

'htmlOptions'=>array('style'=>'$data["style"]'),

But the output is:

<td style="$data["style]">Value</td>

What am I doing wrong?


Solution

  • You can't use $data or $row in htmlOptions. You have to extend the CDataColumn.

    Refer to this article for information on how to do it.