jQuery Selection on HTML Elements within Datatable: Ignore Pagination
jQuery Selection on HTML Elements within Datatable: Ignore Pagination
Hello all,
Description of problem:
I output some hidden HTML content in my rows.
On a table refresh (whereever it is coming from, e.g. from external filtering events, global search or similarly), I want to fetch the data of those hidden HTML elements ignoring pagination. That means: Filtered rows should be ignored, but all the displayed rows from all pages should be considered.
How can I do this?
Link to test case:
http://live.datatables.net/deludodu/1/edit?html,css,js,console,output
Setting pageLength == 25, gives me both elements in the console output (foobar2 is on page 2 if chosing pageLength==10).
After redrawing:
{attr: "foobar"}
{attr: "foobar2"}
When setting back to pageLength == 10, it only yields the {attr: "foobar"} element, but I would be expecting also foobar2 (as I said: is on page 2, but not filtered out).
Only when filtering, I would only expect the visible rows (but again: from all pages).
Thanks so much in advance!
Error messages shown:
N/A
This question has an accepted answers - jump to answer
Answers
The only rows in the DOM are the rows shown on the page. You will need to use Datatables APIs to access the HTML for each row. One option is to use
rows().every()
to itereate each row androw().node()
to get thetr
element. Here is an example:http://live.datatables.net/deludodu/2/edit
Kevin
Thank you for your help once more Kevin, highly appreciated.
Unfortunately, iterating over the rows like this, will not take the filtering into account, i.e. it will give me ALL rows. I just want the rows of ALL pages, but only the ones which are "visible", i.e. not removed by a filter.
i.e. when filtering for "Ashton", I want to only select "fooBar" via jQuery.
Any way to achieve this?
Okay, found a post here on the board:
https://datatables.net/forums/discussion/66027/rows-every-only-for-visible-rows
Final solution:
http://live.datatables.net/deludodu/3/edit
Should be fine, right, or do you see any stumbling block using it like this?
Thanks!
Using the
selector-modifier
of{filter: 'applied'}
is the correct solution.Kevin