Cannot select row on another page
Cannot select row on another page
jdoens
Posts: 18Questions: 4Answers: 0
Hi everyone,
I'm trying to select the row where I get a positive match but can't seem to gain focus of the row that I match. Below is my code
...
var dtable = $('#datatable').dataTable().api();
dtable.rows().eq(0).each(function (index) {
var row = dtable.row(index);
var data = row.data();
if (data.Name == 'John') {
this.addClass("selected");
}
...
I've also tried $(this).closest('tr').addClass('selected') and other variations but haven't had any luck. Any pointers would be greatly appreciated!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I answered my own question. I simply invoked the select() method by row.select().
So it works if the data is found on the first page, but the select doesn't happen if the data is on another page within the DataTable. Is this something I'm doing wrong?
row.show().draw(false) worked.
There isn't a
row.show()
method in DataTables - I'm not entirely sure how that is working unless you have a plug-in method? Perhaps you can link to a page showing the issue?Allan
Sorry for the late reply. I am using a plugin for the show method. https://cdn.datatables.net/plug-ins/1.10.16/api/row().show().js
Ah I see. Yes you would need to call
draw()
and passfalse
so it doesn't reset the paging.Allan