When I run this code, the if statement under onClick evaluates when view.checked == true, but the else does not evaluate when view.checked == false. The alert shows that view.checked seems to be working properly. No idea what's going on. I'm using these two plugins:
https://datatables.net/ with fnFilter plugin
and
http://wenzhixin.net.cn/p/multiple-select
As a side note, also trying to figure out why my .join() method adds spaces.
var checked = [];
var checkedreg = '';
$(document).ready(function() {
rtable = $('#ropes').dataTable( {
"ajax": "data/ropes.txt",
"dom": 'C<"clear">lfrtip',
"columns": [
{ "data": "brand" },
{ "data": "model" },
{ "data": "length" },
{ "data": "dia" },
{ "data": "price" },
{ "data": "drytreat" },
{ "data": "midmark" },
{ "data": "bipat" },
{ "data": "falls" },
],
});
$('select').multipleSelect({
onClick: function(view) {
checkedreg = '';
alert(view.checked);
if (view.checked) { //if checkbox is checked
checked.push(view.label); //add value of checkbox to "checked" array (ex. "Petzl")
}
else {
checked.splice(array.indexOf(view.label), 1); //if checkbox is not checked, remove value from array
alert(checked); //test
}
checkedreg = checked.join("|"); //create regex of values ("Petzl| Mammut| Edelweiss)"
checkedreg = checkedreg.replace(/\s+/g, ''); //for some reason it adds spaces so i have to remove them
alert(checkedreg); //test
alert(checked); //test
rtable.fnFilter(checkedreg, 0, true); //filters a column based on a regex and column index
}
})
});
Replace checked.splice(array.indexOf(view.label), 1);
with checked.splice(checked.indexOf(view.label), 1);
and try