Set filter checkboxes on page load
Set filter checkboxes on page load
![dtsc](https://secure.gravatar.com/avatar/32f937efa632f8a582fc7fa66a7a37a2/?default=https%3A%2F%2Fvanillicon.com%2F32f937efa632f8a582fc7fa66a7a37a2_200.png&rating=g&size=120)
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!