CGridview Conditional Formating

Hi, my best regards.

I have a model and a CGridView associated to this model. The model has a field called PRIORITY which could have the values 1, 2 or 3.

I want that in my CGridView when i show the data, if the record has a 1 value, the row’s background be RED, if 2 gray, if 3 yellow (for example).

How can i do this?

Thanks for your help

Hi, i supposed that because my question was kind of silly nobody replied, jejeje. Nevertheless, i figured out how to do it, and i share here for someone which can’t find how to do it, as i couldn’t a few days ago :P.




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

'id'=>'viajes-grid',

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

'filter'=>$model,

'rowCssClassExpression'=>'Prioridades::model()->findByPk($this->dataProvider->data[$row]->prioridad)->cssclass',

'columns'=>array(...)

array('class'=>'CButtonColumn'

,)

,)

,)); ?>



In the model ‘Prioridades’ i have one field which defines which css class will be applied to the row. Each row of the CGridView has a field which stands for the Id of the model Prioridades. So, i just map this Id between both models, and apply the corresponding ‘cssclass’ to this Id.

Regards…