I am struggling with a feature where I would like to switch datatables on/off with a checkbox using jQuery.
It actually works if I have no datatable defined, then I turn it on/off without problems.
But I would like for the datatable to be on by default and only then to turn it off and back on. I am getting reinitialize warnings.
I have something like this:
$('#datatable-switch').on('click',function(){
if($(this).attr('data-click-state') == 0) {
$(this).attr('data-click-state', 1);
showLockersDataTable();
} else {
$(this).attr('data-click-state', 0)
lockersTable.DataTable().destroy();
}
});
destroy()to destroy an old table before re-initializing a new one.DataTable()whererdestroy()was used with it or not, and so count as re-initation, because in the documentation you linked theDataTableis stored to a variable anddestroy()is used on the variable rather than usingDataTable()again. But it works just the same way, as you can see in my JSFiddle.