I have a datatables table, some of the rows in my table have the class banned. I want to exclude these rows on page load, show them when a checkbox is checked, and exclude them again if the checkbox is unchecked.
Here is my code so far
<div class="field">
<div class="ui toggle checkbox">
<input type="checkbox" id="display_banned_songs" tabindex="0" class="hidden">
<label>Display Banned Songs?</label>
</div>
</div>
$('.ui.toggle.checkbox').checkbox({
onChecked: function() {
console.log('onChecked called');
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
return true;
}
);
},
onUnchecked: function() {
console.log('onUnchecked called');
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
return !$(table.row(dataIndex).node()).hasClass('banned');
}
);
},
onChange: function() { table.draw() }
});
Currently, the rows are not excluded on page load, so I know that my onUnchecked method works, because I can see the rows on page load but when I check and then uncheck my checkbox, the specified rows are hidden and everything else shows.
I can't figure out why my onChecked function doesn't work, I basically need it to display all the rows (unless filtered by the search bar).
I'm also not sure how to hide the specified rows on page load.
How can I get my onChecked method working, and how can I hide the rows on page load?