Check the box for datatables filters

Does anyone have examples of creating a Datatablest filter filter? I want to display only rows that have a value above X or below Y, controlled by a checkbox.

+5
source share
2 answers

You will need to write your own filter function, but after that the code will be simple

$(document).ready(function() {
    $.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
        var checked = $('#checkbox').is(':checked');

        if (checked && aData[4] > 1.5) {
            return true;
        }
        if (!checked && aData[4] <= 1.5) {
            return true;
        }
        return false;
    });
    var oTable = $('#example').dataTable();
    $('#checkbox').on("click", function(e) {
        oTable.fnDraw();
    });

});​

script http://jsfiddle.net/nicolapeluchetti/WVYNX/2/

+15
source

This is exactly what I was looking for, but when I click on a few checkboxes, it does not add filters. Could you help me? Thank.

0
source

All Articles