How to filter Datatable with default checked checkbox

How to filter Datatable with default checked checkbox

mihalispmihalisp Posts: 127Questions: 22Answers: 0

Hello,
i use the following to filter the datatable.The checkbox's default value is "not checked".It works fine.

But when the datatable loads,i want it to be filtered by the checkbox which i want it to be checked by default and show only the 'active' employees.

       $('input:checkbox[name="chk_active"]').on('change', function () {
       //build a regex filter string with an or(|) condition
       var filter = $('input:checkbox[name="chk_active"]:checked').map(function() {
       return this.value;
       }).get().join('|');

      table.column(1).search(filter ? '^((?!0).*)$' : '', true, false, false).draw(false); // active:1 disabled:0

});

Thank you.

This question has an accepted answers - jump to answer

Answers

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    Allan,Colin??Any help please?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,769
    edited April 2019 Answer ✓

    The searchCols is used for defining an initial Datatables column search. See if it will work for you.

    Kevin

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    Yes, 'searchCols' did the trick!
    Thank you so much!

This discussion has been closed.