我看到一个其他人有同样的问题(jquery tablesorter ajax table only sorting one direction),但它不是同一个原因。Mottie jQuery Tablesorter fork自定义排序只排序一个方向
使用jQuery的tablesorter(https://github.com/Mottie/tablesorter)的叉使用数据属性进行排序通过定制解析器的柱(法国日期/时间):
<td data-since="28-09-2012 15:41:10">
<strong>4 jours, 16 minutes</strong> (28-09-2012 15:41:10)
</td>
我可排序ascendantly成功的列,但当我尝试再次单击列标题时,插件不会降级排序。
具有基本数据格式的其他列在两个方向上都正确排序。
下面是基于自定义的分析程序,美国商务部和其他计算器帖子:
$(document).ready(function() {
//https://stackoverflow.com/questions/9550354/jquery-tablesorter-plugin-secondary-hidden-sorting
$.tablesorter.addParser({
// set a unique id
id: 'parseSinceColumn',
is: function(s) {
return /\d{1,2}-\d{1,2}-\d{1,4} \d{1,2}:\d{1,2}:\d{1,2}/.test(s);
},
format: function(s, table, cell, cellIndex) {
// get data attributes from $(cell).attr('data-something');
var cellDate = $(cell).attr('data-since');
s = s.replace(/\-/g," ");
s = s.replace(/:/g," ");
s = s.split(" ");
return new Date(s[2], s[1]-1, s[0], s[3], s[4], s[5]).getTime();
},
// set type, either numeric or text
type: 'numeric'
});
$("#pr-table").tablesorter({
headers : {
3 : { sorter: 'parseSinceColumn' }
}
});
});
你有在途中的任何想法解决这个问题?
非常感谢。
编辑:
我觉得插件真的试图解决,但结果是一样的。
这里是插件的调试:
- 首先排序,成功:
排序上3,1和dir 1次(8毫秒)
重建表( 3毫秒)
完成施加部件(0毫秒)
- 第二排序,在排序没有changement:
排序上3,0和dir 0时间(7毫秒)
重建表(3毫秒)
完成施加部件(0毫秒)