datatables create filter checkbox

泪湿孤枕 提交于 2019-11-29 20:06:23

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/11226614/datatables-create-filter-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!