如何为 CGridView 的每个表行分配唯一的 id 属性? [英] How to assign unique id attribute to each table row of a CGridView?

查看:30
本文介绍了如何为 CGridView 的每个表行分配唯一的 id 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为 Yii 的 CGridView 中的每个表格行分配一个唯一的 ID.

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

最好是类似于数据库表中的 $data->id.

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

我未能成功为每个渲染的 添加 id 属性.

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

任何建议将不胜感激.

推荐答案

CGridView 有一个名为 'rowHtmlOptionsExpression' 的选项,你可以像下面这样声明为行分配一个 id

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

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

这比侵入rowCssClassExpression"要好

It's better than hacking into 'rowCssClassExpression'

祝你好运!

这篇关于如何为 CGridView 的每个表行分配唯一的 id 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆