Set filter checkboxes on page load

Set filter checkboxes on page load

dtscdtsc Posts: 2Questions: 1Answers: 0
edited June 19 in Free community support

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

  • keytrapkeytrap Posts: 15Questions: 2Answers: 2
    Answer ✓

    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

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin

    Is there a 'native' DataTables method I should be using instead?

    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

  • dtscdtsc Posts: 2Questions: 1Answers: 0

    Thanks lads!

Sign In or Register to comment.