覆盖表排序器顺序
Override table sorter order
我想重写表排序器上的排序。现在,我的表中有以下动态添加的条目:
1 Active,34 Active, 453 Active, 3235 Active, inactive, inactive
问题是,有另一列,我希望所有的活动项排序,而不是通过它前面的数字。
是否可以用表排序器做到这一点?如果有,那是怎么回事?
好了,我算出来了。我所要做的是使用一个表分析器。然后,我使用正则表达式从Active
字符串中剥离数字和空格。之后我将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'
}
}
});
});
你可以这样做:
$(document).ready(function() {
// call the tablesorter plugin
$("table").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0],[2,0]]
});
});
相关文章:
- Javascript按数字顺序排序()数组
- 用于提示输入和输出的JavaScript按字母顺序排序
- 数组将字母顺序排序到下拉 JavaScript 中
- 循环遍历 json 对象并按顺序排序
- 如何获取按字母顺序排序的标记
- 检索WordPress RSS提要,并按javascript的字母顺序排序
- 角度 - 使用 orderBy in ng-repeat 以递增顺序排序
- 按数字排序列表,然后使用 jQuery 按字母顺序排序
- 如何在不按 DOM 顺序排序的情况下将 jquery 选择添加到一起
- 如何使默认<选项>在Javascript中,同时按顺序排序
- 按字母顺序排序jquery结果
- 从对象数组中提取数据并按字母顺序排序(同时)
- 按字母顺序排序javascript填充的选择列表
- 按字母顺序排序
- 按字母顺序排序列表项
- 在咖啡脚本中按字母顺序排序
- 按字母顺序排序Jquery列表
- 使用jquery,根据日期按时间顺序排序JSON,最新的在前
- 按姓氏按ASC或DESC顺序排序表
- Angularjs ng-repeat按数字顺序排序字符串数组