JQuery表排序器特殊日期
我有一个存储术语信息的表,如下所示: 2018年温特,2017年SPR 我想按addParser对术语列进行排序。我所指的方式如下: 我的计划是将术语信息更改为日期,并对日期进行排序 我的代码在这里:JQuery表排序器特殊日期,jquery,date,plugins,tablesorter,Jquery,Date,Plugins,Tablesorter,我有一个存储术语信息的表,如下所示: 2018年温特,2017年SPR 我想按addParser对术语列进行排序。我所指的方式如下: 我的计划是将术语信息更改为日期,并对日期进行排序 我的代码在这里: $(function(){ $.tablesorter.addParser({ // set a unique id id: 'term', is: function(s) { // return false so this parser is not auto detec
$(function(){
$.tablesorter.addParser({
// set a unique id
id: 'term',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.toLowerCase()
.replace(/wint /, /Jan 01, /)
.replace(/sumr /, /Jul 01, /)
.replace(/spr /, /Mar 01, /)
.replace(/fall /, /Sep 01, /);
},
type: 'date'
});
$(".tablesorter").tablesorter({
headers: {
1: { sorter: "term" }
}
}
);
});
结果是,术语列被冻结,而其他列则良好
我关注的是两点,
1.替换格式正确吗?我在网上找不到替换示例。
2.类型:“日期”正确吗?它应该是文本还是数字
有没有人有过类似的经历?任何提示都将不胜感激 我发现该类型仅适用于数字和文本。我可能是错的,但我坚持数字,并放弃改变它的日期 代码在这里,它对我有用
$.tablesorter.addParser({
// set a unique id
id: 'term',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
text = s.split(' ');
s=text[1] + text[0];
return s.toLowerCase()
.replace(/wint/, 1)
.replace(/sumr/, 7)
.replace(/spr/, 3)
.replace(/fall/, 9);
},
// set type, either numeric or text
type: 'numeric'
});
$(".tablesorter").tablesorter({
headers: {
1: { sorter: "term" }
}
}
);
谢谢大家! 这应该行得通。解析器被设置为“numeric”,将解析的值作为一个数字进行排序,但它返回一个字符串值;只要数字小于10,这仍然不会导致任何问题。至于在线演示,请查看。