How To Assign Dynamic Data To Cdatacolumn Htmloptions

I have a CGridView table. I would like to add data-id attribute to the <td> element. Looking at the CDataColumn I have the following column:



                    'name'  => 'article_title',

                    'value' => '$data->article_id . ". " . $data->article_title',

                    'htmlOptions' => array("data-id" => $model->article_id),



htmlOptions from the above code fail as $model->article_id is null. How can I access the value of the current data row?


CGridView::$rowHtmlOptionsExpression was added in 1.1.13:





Yes, it needs to be an array inside a string.

This is not what I am looking for. This adds data-id to the <tr> element and i need to add data-id to the <td> element so I just need to understand how htmlOptions on the columns work with dynamic data!

htmlOptions doesn’t work with dynamic data. article_id is part of a row in your database, so you can only attach it to the row element in your HTML table. It’s easy to get the value from within the column.