Is There Css Class Expression For Column In Cgridview?

Hi,

I know the rowCssClassExpression for rows, but I can’t find for columns in cGridView.

Now, I need that, if some conditions are met, the background of the columns have to change to other color.

Do you know an easy way to create, or implement an column css class expression? Or what will be the best way for my problem in Yii?

There’s an attribute ‘cssClassExpression’ in CGridColumn with description “a PHP expression that is evaluated for every data cell and whose result is used as the CSS class name for the data cell”. This class will render the cells of the column it’s representing. This will do the trick for you.

CGridColumn class reference

This class is what you are adding when initiating an CGridView, see examples in admin.php files in the view folder, or see this example (the columns item is where you can add different types of column classes, default is CGridView if the value is a string):


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

   'id'=>'user-grid',

   'dataProvider'=>$model->search(),

   'filter'=>$model,

   'columns'=>array(

       'id',

       'name',

      array(

         'class'=>'CLinkColumn',

        'cssClassExpression'=>"$data->isX()?'classa':'classb';"

     )

    )

);