Using Checkboxes as a filter
Using Checkboxes as a filter
Hi,
I intend to use a set of checkboxes to filter my datatable rows, not columns. My datatable basically shows list of projects with few different categories, and I want to provide an option at the top to select the categories I want to see (one or more). The checkboxes are not part of the datatable.
As suggested by someone, I have created this function that I invoke when a checkbox is clicked:
function checkBoxClicked() {
var reg_exp = '';
var checkboxs = document.getElementsByName('filter');
for(var i = 0, inp; inp = checkboxs[i]; i++) {
if (inp.type.toLowerCase() == 'checkbox' && inp.checked) {
reg_exp = reg_exp + inp.value + '|';
}
}
if (reg_exp == '') {reg_exp = 'X|' }
oTable.fnFilter( reg_exp.slice(0, -1),8, true );
}
I have a few checkboxes named 'filter', and the unique value of each is the name of the category. So the idea is to display only the categories for which the corresponding checkboxes are checked. But the table doesn't get redrawn upon checking/unchecking the checkboxes. I would ideally like to have the table redrawn on every checkbox click, but if there is an easier way to first check all the checkboxes, then hit a submit button, and then redraw the table, I am fine with that too. I have seen a couple of closed discussions on the similar issues, but no concluding solutions.
Any suggestions?
Many thanks,
Aalap
I intend to use a set of checkboxes to filter my datatable rows, not columns. My datatable basically shows list of projects with few different categories, and I want to provide an option at the top to select the categories I want to see (one or more). The checkboxes are not part of the datatable.
As suggested by someone, I have created this function that I invoke when a checkbox is clicked:
function checkBoxClicked() {
var reg_exp = '';
var checkboxs = document.getElementsByName('filter');
for(var i = 0, inp; inp = checkboxs[i]; i++) {
if (inp.type.toLowerCase() == 'checkbox' && inp.checked) {
reg_exp = reg_exp + inp.value + '|';
}
}
if (reg_exp == '') {reg_exp = 'X|' }
oTable.fnFilter( reg_exp.slice(0, -1),8, true );
}
I have a few checkboxes named 'filter', and the unique value of each is the name of the category. So the idea is to display only the categories for which the corresponding checkboxes are checked. But the table doesn't get redrawn upon checking/unchecking the checkboxes. I would ideally like to have the table redrawn on every checkbox click, but if there is an easier way to first check all the checkboxes, then hit a submit button, and then redraw the table, I am fine with that too. I have seen a couple of closed discussions on the similar issues, but no concluding solutions.
Any suggestions?
Many thanks,
Aalap
This discussion has been closed.
Replies
Allan