CgridView Row Decoration

Is it possible to decorate a row in a CGridView, for example if $data->accepted==1 then that row should be in bold.

I think this is what you need

http://www.yiiframework.com/doc/api/1.1/CGridColumn#cssClassExpression

/Tommy

Edit: if you want to highlight a single cell, that is :rolleyes: . I’ll continue too look for the correct answer.

Edit2: Ok, this is one way I think it can be done:

  1. use the cssClassExpression property

  2. client side, use jQuery to select it

  3. find the surrounding tr tag and add a suitable css class to it.

Edit3: trying to find a way to have this executed from the column definition (CDataColumn assumed):




$this->grid->rowCssClassExpression = "bold"



Edit4:

This hack should work (I really miss the comma operator from C/C++)




'cssClassExpression' => ' "" + ($data->accepted == 1) ?  (($this->grid->rowCssClassExpression = "bold")?"":"") : (($this->grid->rowCssClassExpression = "normal") ?"":"")',



I think the next approach would be to extend CGridColumn.

Right I’ve tried doing it like this in the CGridView:


'rowCssClassExpression'=>'$data->accepted==1 ? "bold" : "normal"',

This applies the correct CSS class, however the default ‘odd/even’ classes are now not rendered.

There must be a way I can have it retain the default class and add an additonal class as required.

You can try with something like:




'rowCssClassExpression'=>'($row%2 ? "even" : "odd"). .($data->accepted==1 ? "bold" : "normal")',



I just came to the same conclusion (with just one dot between).

(In my previous post, :rolleyes: ,I didn’t think about that $data is available throughout the row while rendering the widget. Client-side it’s different.)

/Tommy

The doc states that you can use $data, $row and $this in the expression (even if I can’t immagine the need of using $this in such a context…).

I just ran into the same problem and inserting the second row condition statement into the false case of the first one seems to work




'rowCssClassExpression'=>'$data->accepted==1 ? "bold ". ($row%2 ? "even" : "odd") : ($row%2 ? "even" : "odd")'



now it should be bold + (odd or even) or (odd or even)

hello , i need to hilight the search keyword in gridview results…is this possible in yii??