Primefaces - Select Datatable line via Jquery, Javascript or PF

Asked

Viewed 344 times

2

How do I select a line from a Datatable, using Jquery, pure Javascript or the PF javascript command?

1 answer

1


Note: It is not a very elegant solution, but it solves your problem.

You can directly select a column in the desired row of the datatable via jQuery and then call the event. click()

Example:

$('#form\\:singleDT_data tr[data-ri=4] td').click()

Explaining:

First you select the datatable via jQuery $('#form\\:singleDT_data) (do not forget to escape the two points with bar bar (\\:).

Then select a table row using the data-ri attribute and pass the index as argument:$('#form\\:singleDT_data tr[data-ri=4]).

Finally, select a column element of the result and call . click() $('#form\\:singleDT_data tr[data-ri=4] td').click().

You can test this solution directly on Showcase of Primefaces

The example will select line 5 of the datatable "Single with Row Click".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.