更新 #2:从tablesorter v2.17.0 开始,可以使用类名*或 ID 来定位filter_functions选项中的列:
// filter functions
widgetOptions: {
filter_functions : {
".exact" : function(e, n, f, i) {
return e === f;
}
}
}
* 注意:类名不能包含使用任何类型索引的选择器,例如"th:eq()", ":gt()", ":lt()", ":first", ":last", ":even"or ":odd", ":first-child", ":last-child", ":nth-child()",":nth-last-child()"等。
在docsfilter_functions中,它显示了使用该选项的替代方法:
或者,不要将列过滤器函数设置为 true,而是为列标题指定一个类名“filter-select”。请参阅演示。
因此,只需将filter-select类名添加到列中即可。
更新:由于正在使用其他过滤器函数,您可以在初始化代码之外定义这些函数(演示)
// Add these options to the select dropdown (date example)
// Note that only the normalized (n) value will contain
// the date as a numerical value (.getTime())
var dateFxns = {
// Add these options to the select dropdown (date example)
// Note that only the normalized (n) value will contain
// the date as a numerical value (.getTime())
"< 2004": function (e, n, f, i) {
return n < Date.UTC(2004, 0, 1); // < Jan 1 2004
},
"2004-2006": function (e, n, f, i) {
return n >= Date.UTC(2004, 0, 1) && // Jan 1 2004
n < Date.UTC(2007, 0, 1); // Jan 1 2007
},
"2006-2008": function (e, n, f, i) {
return n >= Date.UTC(2006, 0, 1) && // Jan 1 2006
n < Date.UTC(2009, 0, 1); // Jam 1 2009
},
"2008-2010": function (e, n, f, i) {
return n >= Date.UTC(2008, 0, 1) && // Jan 1 2006
n < Date.UTC(2011, 0, 1); // Jam 1 2009
},
"> 2010": function (e, n, f, i) {
return n >= Date.UTC(2010, 0, 1); // Jan 1 2010
}
},
currentDateColumn = 3,
filterFxn = {};
filterFxn[currentDateColumn] = dateFxns;
$('table').tablesorter({
widgets: ['zebra', 'filter'],
widgetOptions: {
filter_functions: filterFxn
}
});