Reputation: 7051
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.
Upvotes: 6
Views: 20366
Reputation: 76890
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/
Upvotes: 18