I have a table made with datatables. There is checkbox, which, when clicked filters the table to display only the data I want to see. The problem is that when I uncheck the checkbox, the table becomes buggy. The table.destroy() function does seemingly revert the table back to the way it was, although it looks like it destroys a little too much (rows per page suddenly get ignored + can no longer click on cell, which opens up in another window).
This is what happens: 1. click on checkbox: filters the data correctly 2. uncheck checkbox: table looks as if gone back to normal (but hasn't really) 3. check checkbox again: no longer filters data correctly. (table is now empty) 4. now it doesn't matter if I check or uncheck, the table stays the same(empty)
Here is my code:
var checkbox = $("#checkB");
checkbox.click(function () {
var table = $('#WTM_LOG').DataTable();
if (checkbox.is(":checked")) {
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var num = Number(data[4]);
if (num > 0) {
return true;
}
return false;
}
);
table.draw();
}
else {
table.destroy();
}
});
Aucun commentaire:
Enregistrer un commentaire