Skip to content
Advertisement

Custom SelectAll checkbox only select elements from current DataTable page

I have a simple and basic DataTable which I added a thead with a custom SelectAll checkbox and another ones for each row existing in my tbody (I need to add this input because I’m attaching some data attributes, validations, events, etc. on it, based on the rows) that’s why I cannot add the checkbox column on the .DataTable({}) config. At the moment everything it seems to work, the only problem is that my SelectAll event it’s only working with element on the current page. Ex: If my datatable has 2 pages and I check my SelectAll input with the pagination located at page 1, all rows are selected but only on page 1. My question is if there is a way to handle this keeping the same functionality or what can I do to implement the selectAll without loosing the possibility to attach events to each row.

Here is my code and a working fiddle

JavaScript
JavaScript

Advertisement

Answer

You can use the rows API to do that:

JavaScript
JavaScript
Advertisement