【问题标题】:Primefaces Data table row idPrimefaces 数据表行 id
【发布时间】:2012-11-18 14:50:00
【问题描述】:

如何设置 id(HTML 属性)到 Primefaces 中的 DataTable 行(tr 元素)?
我搜索了,但到处都是如何获取 id。
我需要这个,因为我想将 pf 数据表与rowReordering plugin 集成。

【问题讨论】:

    标签: html jsf datatable primefaces


    【解决方案1】:

    您无法从 PrimeFaces API 设置 Primefaces 数据表中 <tr> 元素的 id,但它似乎不需要行本身具有特定的 id,因此可以在回发后从客户端的 Javascript 执行此操作。

    $(document).ready(function() {
      $('.ui-datatable-data').children().each(function(index, element) {
        element.attr('id', 'foo_' + index);
      };
    };
    

    这将找到 jQuery 和 Primefaces 数据表的每个 tbody 元素,并将 tr 孩子的 id 设置为唯一且可预测的 id。

    【讨论】:

      【解决方案2】:

      我尝试了maple_shaft 的回答并遇到了一些问题。我解决了这些问题,这是我的代码:

      $(document).ready(function () {
         $('.ui-datatable-data').children().each(function (index, element) {
            element.setAttribute('id', 'row_' + index);
         });
      });
      

      现在我的每一行都有自己的 ID,即 'id="row0"'

      【讨论】:

      • 出于好奇,你为什么需要这个? PF 内置了行排序
      猜你喜欢
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多