Set filter checkboxes on page load
Set filter checkboxes on page load
I'm using this code which adds checkboxes that act as filters, placed above a table:
https://live.datatables.net/vipifute/720/edit
I want some checkboxes to be in a checked state when the page loads. The table should be filtered based on the checkbox status.
I've tried a standard Javascript approach that works with standard HTML checkboxes, but cannot get it working with these DataTables checkboxes:
document.getElementById(checkboxId).checked = true;
Is there a 'native' DataTables method I should be using instead?
Many thanks.
This question has an accepted answers - jump to answer
Answers
I woul've done it like that, using the initComplete event and adding a 0ms timeout to be sure eveything is loaded.
https://live.datatables.net/vipifute/726/edit
No because DataTables doesn't provide the checkboxes. What you do need to do is trigger the search to happen when the table is loaded, and
initComplete
with a trigger as @keytrap suggested looks like a good way of doing it without duplicating code.The other option, rather than triggering an event handler would be to have the filtering action in a function and call that both from
initComplete
and the event handler.Allan
Thanks lads!