I have two columns that I want to be filterable with list.js. I tried the following code:
var options = {
valueNames: [ 'formformname', 'form-name', 'form-email','form-phone','form-branch','form-message','formstatus','form-assignment' ],
page: 15,
pagination: [{
outerWindow: 2,
}]
};
var userList = new List('users', options);
$('#origin').change(function () {
var selection = this.value;
if (selection) {
userList.filter(function(item) {
return (item.values().formformname == selection);
});
} else {
userList.filter();
}
});
$('#status').change(function () {
var selection = this.value;
if (selection) {
userList.filter(function(item) {
return (item.values().formstatus == selection);
});
} else {
userList.filter();
}
});
And it works fine for each column, the problem is if I select an 'origin' filter, then a 'status' filter, or vice versa, the second selection wipes out the first one. What I want to do is have them function together. Any ideas?
Following creates an array from the selected dropdowns and uses Array#every() to check each item in the list filter.
Note the addition of the
data-propattribute to each<select>in order to determine which column property to filter for each one