Instead of referencing columns by number, I would like to define filters more dynamically. In particular, I'd like a way to say "all columns with th class xx get filter type yyy". Is that possible?
Dynamic column filters
415 Views Asked by DLynnSmith At
2
There are 2 best solutions below
0

I was able to get this resolved. Posting the code in case it is useful to someone else:
// Set filters
var THs = document.getElementsByTagName("th");
var filterArray = [];
for (i = 0; i < THs.length; i++) {
var colNumber = i;
if ((THs[i].classList.contains('searchText')) || (THs[i].classList.contains('searchSelect')) || (THs[i].classList.contains('searchDate'))) {
if (THs[i].classList.contains('searchText')) {
var colFilter = "text";
}
if (THs[i].classList.contains('searchSelect')) {
var colFilter = "select";
}
if (THs[i].classList.contains('searchDate')) {
var colFilter = "range_date";
}
filterArray.push({column_number: colNumber , filter_type: colFilter});
}
}
yadcf.init(containerTable, filterArray);
Since 0.9.4.beta.10 you can also use the columnDefs and provide yadcf with a
column_selector
instead ofcolumn_number
, see it in action