How to hide specific rows if checkbox is checked.
How to hide specific rows if checkbox is checked.
Hello guys, first of all sorry if i am posting duplicate but didnt find answer for this case.
I have datatable that gets data from ajax , in table there is column name ID.
I have three checkboxes and want to do this:
If checkbox1 is checked then show only rows where ID is greater than zero.
If checkbox2 is checked then show only rows where ID is zero.
If checkbox3 is checked then show all rows.
Could you please tell me what method/function/feature to use in order to achieve this?
Thank you very much for all of your answers.
Answers
You will need to create a search plugin for this. Here is an example:
http://live.datatables.net/wenaxuti/1/edit
Kevin
I tried it but its still not working did i do it correctly?
$.fn.dataTable.ext.search.push(
function (settings, searchData, index, rowData, counter) {
if ( $('#checkbox1').prop('checked') ){
return rowData > 0;
} else if ($('#checkbox2').prop('checked')){
return rowData === 0;
} else if ($('#checkbox3').prop('checked')) {
return rowData;
} else {
return false;
}
}
);
$('.checkboxes').on('change', function () {
table.draw();
});
Kevin's example seems to work just fine for me.
Perhaps you can specify how it isn't working for you? Or if you are having problems reusing the code he suggested, link to the page you are having problems with or create a test case that shows the issue.
Allan