column style in cgridview

Hi,

I need to style a cgridview so that, within a column, some cells are styled in one way and others in another way.

Specifically, I have a column with money values and I’d like to have them displayed red if they are negative values and green if they are positive values.

Any ideas on how may I achieve this?

Thank you

have you tried to play with cgridview’s rowCssClassExpression:

http://www.yiiframework.com/doc/api/1.1/CGridView#rowCssClassExpression-detail

Thanks bettor,

rowCssClassExpression wasn’t what I was looking for since this property manages the row’s css.

Nevertheless you point me to the right direction. In fact I was looking for cssClassExpression property.

For the record, I’m leaving here the fix I was looking for:




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

    'id' => 'journal-grid',

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

    'filter' => $model,

    'columns' => array(

        ...

        array(

            'name'=>'amount',

            'value'=>  'number_format($data->amount/100, 2, ",","." ) . " EUR"',

            'cssClassExpression'=> '($data->amount > 0)? "green": "red"',

        ),

        ...

        array(

            'class' => 'CButtonColumn',

        ),

    ),

));



agh, yes it is the cssClassExpression that I wanted to provide. I’ve copied the wrong property. Anyway, you did the job which is good.