我需要调用fnFilter
方法来使用“OR”运算的过滤功能来过滤第一列。
喜欢
thisObj.dataTable.fnFilter(keywordsArray,0);//TODO, OR FILTER
我将有一个像 ["P1","P2"] 这样的数组,它代表我需要过滤掉的产品代码。
假设我的表包含产品代码 P1,P2,P3 行,当我传递 ["P1", "P2"] 数组时,我需要查看前两行。
最佳答案
您可以使用$.fn.dataTableExt.afnFiltering
来代替。以下函数适用于 1.9.x 和 1.10.x 版本:
//a general filtering function taking an array of values
function filter(values, colIndex, match) {
$.fn.dataTableExt.afnFiltering.push(
function(settings, data, dataIndex) {
for (i=0;i<values.length;i++) {
if (match) {
if (data[colIndex] == values[i]) return true;
} else {
if (data[colIndex].indexOf(values[i])>=0) return true;
}
}
return false;
}
);
table.fnDraw();
$.fn.dataTableExt.afnFiltering.pop();
}
通过按钮激活,在第 3 列上进行完全匹配的过滤:
$("#filter").click(function() {
filter( ['1.7', '1.8'], 3, true );
});
对于问题,调用filter(keywordsArray, 0);
1.9.x 演示 -> http://jsfiddle.net/uu7gcwvf/
1.10.x 演示(相同的代码,不同的库)-> http://jsfiddle.net/hrm97wd0/
如果你想制作一个纯 1.10.x DataTable()
过滤器:
function filter(values, colIndex, match) {
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
for (i=0;i<values.length;i++) {
if (match) {
if (data[colIndex] == values[i]) return true;
} else {
if (data[colIndex].indexOf(values[i])>=0) return true;
}
}
return false;
}
);
table.draw();
$.fn.dataTable.ext.search.pop();
}
关于javascript - "OR"过滤器 `fnFilter` ,数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30299033/