Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables create filter checkbox

Does anyone have examples on how to create a Datatablest filter checkbox? I want to display only rows that have a value above X or below Y being controlled by a checkbox.

like image 684
Astronaut Avatar asked Jun 27 '12 12:06

Astronaut


1 Answers

You would have to write your own custom filtering function but after that the code would be vary 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();
    });

});​

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

like image 137
Nicola Peluchetti Avatar answered Nov 05 '22 10:11

Nicola Peluchetti