I'm trying to set up a checkbox that applies a filter.

I'm trying to set up a checkbox that applies a filter.

ArnioxArniox Posts: 2Questions: 2Answers: 0
edited December 2019 in Free community support

I have a datatables table with a couple of columns and want to apply a filter onto one of those columns at a time, per checkbox.
I want the checkboxes styled with the bootstrap "custom-switch" style and with a custom label (as well as other styling)

At default the checkboxes should be checked and the column it's checking needs to match a specific string for "Sales Complete". Every other data entry in that column has different strings.
When unchecked, the user should be able to view data entries that have "Sales Complete" and when checked, the user will not be able to view these data entries.

I tried this following code but it doesn't work and I'm not sure how to get it working:

//Re-draw table on click
    $(document).ready(function () {
        var table = $('#currentSalesTable').DataTable();

        //Event listener
        $('#viewCompletedSales').click(function () {
            table.draw();
        });

        var filteredData = table
            .columns(3)
            .data()
            .filter(function (value, index) {
                return value == "Sale Complete" ? true : false;
            });
    });

I'm still very new to JQuery, so please give detailed answers thanks :)

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.