How to assign unique id attribute to each table row of a CGridView?

bjtilley picture bjtilley · Jun 18, 2012 · Viewed 7.9k times · Source

I am attempting to assign a unique id to each table row in Yii's CGridView.

Preferably something like $data->id from the database table.

I have been unsuccessful at adding an id attribute to each rendered <tr>.

Any suggestions would be most appreciated.

Answer

Chung picture Chung · Sep 10, 2013

CGridView have an option called 'rowHtmlOptionsExpression' , you can declare like the followings to assign row an id

'rowHtmlOptionsExpression' => 'array("id"=>$data->id)',

It's better than hacking into 'rowCssClassExpression'

Good luck !