zii.widgets.grid.CGridView Style


I have a zii.widgets.grid.CGridView bind to a model at form that generates from GII,

All I need to do that how can I give colors to the grid row according to a model filed, it’s like color coding for the grid rows.

Here you are my code

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
















)); ?>

According the value of ‘STATUS_ID’ I need to set a color, How?

please help :)

Is this what you want ?


    .red {background: red}

    .green {background: green}


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




        'rowCssClassExpression' => '$data->status==="3"?"red":"green"',




It’s working…

many thanks for you Rookie.

but if there is more than one value, how can I code that expression (status values 1,2,3,…)

these values comes from the database, and the colors as well.

do we have a solution for it

again, many thanks for your help

Yes there’s a solution: use some common sense, research a little, its pretty easy… or you want me to have this assignment done for you? ;)

sure nvm, I’ll do it my self

Good, thats how you learn…

why you use $data not $model