0
我使用tablesorter(https://mottie.github.io/tablesorter/docs/index.html) 排序我的HTML表格。在tablesorter中自定义排序顺序 - jquery
我有一个排序我找不到howtoo。即。
- (4)
- (DNS)
- DNS
要被分类为:
- (4)
- (DNS)
- DNS
简言之:()将被忽略,并且数字排序,首先数字然后按字母顺序。
我已经看过如何替换字符,(因为某些排名不工作,因此为“空”) 我见过的解析器要求我创建每个标题和已知值以替换。 即:
$.tablesorter.addParser({
id: 'nummeriek',
is: function(s) {
return false;
},
format: function(s) {
// format your data for normalization
return s.toLowerCase().replace('dns',999).replace('(dns)',999).replace('(4)',4);
},
type: 'numeric'
});
$('.tablesorter').tablesorter({
headers: {
6: {
sorter:'nummeriek'
}
}
});
如果我必须为每一个可能的表的内容我最终创造数百替换()语句的做到这一点。因为我的分数从1到100因此(1)到(100)也是可能的...
必须有一个更简单的方法。任何帮助深表感谢。
现在,这真棒。谢谢! – Pieter
我剩下的一件事就是涉及的标题数量。由于这是一列表,我可以很容易地有一个2,8,12列的可变数量。我尝试了我在这里找到的addClass方法:https://stackoverflow.com/questions/9014962/jquery-tablesorter-custom-parser-to-all-headers,但我无法得到它适用于所有专栏..我是否缺少什么? – Pieter
哎呀,对不起,我错过了你的问题。在'headers'选项中,您可以使用jQuery选择器来定位列而不是从零开始的索引 - 'headers:{'.nummeriek':{sorter:'nummeriek'}}'([example](https://mottie。github.io/tablesorter/docs/example-options-headers.html))。或者,向需要它的每一列添加一个“sorter-nummeriek”类。 – Mottie