Using Checkboxes as a filter

Using Checkboxes as a filter

aalapkaalapk Posts: 4Questions: 0Answers: 0
edited September 2012 in General
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

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    That looks like it should work on a first scan. Perhaps you can give us a link to the page please? Assuming the reg_exp variable is being constructed correctly (use console.log to confirm that it is) the fnFilter call you have should be filtering the table.

    Allan
This discussion has been closed.