m.dhouibi
(Mohamed Dhouibi1985)
1
Hello
I am using widgets.TbGridView,
I have a column "priority" values are 0,1, or2
I need to use css for every row depending to priority value.
How I can use rowCssClassExpressionin in this case, because all the example I can find is a condition sentence as :
'rowCssClassExpression'=>'($data->color==0)?"white":"pink"',
m.dhouibi
(Mohamed Dhouibi1985)
2
If I try to use a function example:
'rowCssClassExpression'=>getCssClass($data["priority"]),
I get the error Undefined variable: data
Keith
(Kburton)
3
You could do it in several ways, but here are two that I think will work:
// Option one: evaluate as a string
'rowCssClassExpression'=>'getCssClass($data["priority"])',
// Option two: use an anonymous function
'rowCssClassExpression'=>function($row, $data){
return getCssClass($data['priority']);
},
paalgg
(Paalgg)
4
I think the best solution is to make a function in the model that outputs the class name, and you call it like this:
...
'rowCssClassExpression'=>'$data->getCssClass($row)',
...