Hi everyone,

I need help with rowCssClassExpression in CGridView. I need to use very long expression with a lot of cases and doing it like

'rowCssClassExpression'=> 'one_case ? ((second_case) ? "one" : "two") : "three"'

seems not good enough, becouse in more cases it will be very long.

I want to replace expression with some method of model but it didnt work for me, I know that expression need $row and $data so how can i pass this from my method? I see that CgridView class evaluateExpression like:


I dont know if it’s possible to write expression with method if so please be so kind and help me with some example or any other advice how to solve this problem.

Use an anonymous function. Here’s an example that I use in one of my grids:

	'rowCssClassExpression'=>function($row, $data) use ($basket){

		$class = $row % 2 ? 'even' : 'odd';

		if (isset($basket[$data['ITEMID']]))

			$class .= ' selected';

		return $class;


Thanks, this is exactly what i need. You saved my day :P