Checkbox checked on filtered rows
Checkbox checked on filtered rows
Hi
I am using datatable 1.9.4 (can't upgrade to 2.0 for various reasons).
I am trying to set checked state on checkboxes in a filtered dataTable that (can) span multiple pages by clicking on a Select All button. This button is supposed to set the checked state on all filtered data only.
I can only get my code to set the checked state on the checkboxes on the first page (maybe visible rows?) but any checkboxes on subsequent pages remain unchecked.
I have added a fiddle here: http://jsfiddle.net/ohj8t5kL/2/
To test: enter spain in the filter box. Below variable (filteredRows) now contains 4 rows:
// contains 4 rows for Spain
var filteredRows = $(dtTable).dataTable()._('tr', { "filter": "applied" });
However, when I loop these 4 rows with the following code, only items on the first page of the dataTable is set.
// only 3 rows checked:
filteredRows.forEach(function (row) {
$('#mytable input[value="' + row[0] + '"]').prop('checked', checked);
});
Hoping for some advice
Best
Perelli.
Answers
I know you just define the data in your fiddle, but in your version are you using server-side data?
Thanks for replying - I am using server-side data but just added pure JSON here for clarity.
I just found the solution and now it works using the fnGetFilteredNodes from here:
http://www.datatables.net/forums/discussion/20058/complete-solution-passing-filtered-and-or-paginated-form-fields-with-optional-check-all-feature#latest
I simply changed the selectAll method to: