user1756277
user1756277

Reputation: 207

Primefaces Data table row id

How can I set id (HTML attribute) to DataTable row (tr element) in Primefaces ?
I searched, but everywhere is how get id.
I need this because I want integrate pf data table with rowReordering plugin.

Upvotes: 3

Views: 3405

Answers (2)

willemlab
willemlab

Reputation: 73

I have tried maple_shaft's answer and got a few issues. I fixed the issues and here is my code:

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

Now each of my rows has its own ID as 'id="row0"'

Upvotes: 0

maple_shaft
maple_shaft

Reputation: 10463

You can't set the id of the <tr> elements in the Primefaces data table from the PrimeFaces API, but it doesn't appear as if it requires the rows themselves to have a specific id, so it is possible to do this from Javascript at the client side after a postback.

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

This will find every tbody element for jQuery and Primefaces datatables and set the id of the tr children to a unique and predictable id.

Upvotes: 3

Related Questions