Javascript 覆盖表格分拣机订单
我想覆盖tablesorter上的排序。现在,我的表中动态添加了以下条目:Javascript 覆盖表格分拣机订单,javascript,jquery,tablesorter,Javascript,Jquery,Tablesorter,我想覆盖tablesorter上的排序。现在,我的表中动态添加了以下条目: 1 Active,34 Active, 453 Active, 3235 Active, inactive, inactive 问题是,我希望所有活动条目都按另一列排序,而不是按前面的数字排序 是否可以使用桌面分拣机进行此操作?如果是这样,怎么做?您可以这样做: $(document).ready(function() { // call the tablesorter plugin $("table").tabl
1 Active,34 Active, 453 Active, 3235 Active, inactive, inactive
问题是,我希望所有活动条目都按另一列排序,而不是按前面的数字排序
是否可以使用桌面分拣机进行此操作?如果是这样,怎么做?您可以这样做:
$(document).ready(function() {
// call the tablesorter plugin
$("table").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0],[2,0]]
});
})) 好吧,我想起来了。我要做的是使用表排序器解析器。然后,我使用正则表达式去除
活动
字符串中的数字和空格。之后,我将inactive
替换为值1,将active
替换为值2。然后我可以将我的表从活动和非活动类别中排序,并根据另一列进行进一步排序。代码如下:
$.tablesorter.addParser({
//give an id to the parser
id: 'campaigns',
is: function(s) {
return false;
},
format: function(s) {
//remove any numbers and spaces in the string s
var state = s.replace(/[0-9]/g, '').replace(/\s/g, '');
//change inactive to a 1 and active to a 2
return state.toLowerCase().replace(/inactive/,1).replace(/active/,2);
},
//sort on a numeric type
type: 'numeric'
});
$(function() {
$("table#game-data-table").tablesorter({
//sort based off of active inactive, then off column 4,and finally off column 1
sortList: [[1,1], [3,1], [0,0]],
headers: {
1: {
sorter: 'campaigns'
}
}
});
});
看一看。可能是你想要的。@PatrickQ这不是我想要的。我试图澄清这个问题。是的,这就是我现在正在做的,但问题是它首先对整个第一栏进行排序,然后对第三栏进行排序。我希望它在第一列中仅按active或inactive排序,然后在第三列中排序。但是,如果某个字段处于活动状态,则它前面有一个数字。所以它看起来像是10个活跃的。我基本上需要表分拣机忽略前面的数字活跃。你知道怎么做吗?在format函数中使用它会更“干净”:
return/inactive/i.test?1 : 2;代码>