如何在 Primefaces 中将 id(HTML 属性)设置为 DataTable 行(tr 元素)?
我搜索过,但到处都是如何获取 id。
我需要这个,因为我想将 pf 数据表与rowReordering 插件集成。
问问题
2670 次
2 回答
3
您无法<tr>
从 PrimeFaces API 设置 Primefaces 数据表中元素的 id,但它似乎不需要行本身具有特定 id,因此可以在 Javascript 中执行此操作回发后的客户端。
$(document).ready(function() {
$('.ui-datatable-data').children().each(function(index, element) {
element.attr('id', 'foo_' + index);
};
};
这将找到 jQuery 和 Primefaces 数据表的每个 tbody 元素,并将子项的 id 设置为tr
唯一且可预测的 id。
于 2012-11-30T12:19:55.110 回答
0
我已经尝试了 maple_shaft的答案并遇到了一些问题。我解决了这些问题,这是我的代码:
$(document).ready(function () {
$('.ui-datatable-data').children().each(function (index, element) {
element.setAttribute('id', 'row_' + index);
});
});
现在我的每一行都有自己的 ID 为 'id="row0"'
于 2019-08-22T14:16:48.570 回答