Mottie jQuery Tablesorter fork自定义排序仅对一个方向进行排序
我看到另一个人也有同样的问题,但原因不同 我使用jQuery Tablesorter()的fork,通过使用数据属性的自定义解析器(法语日期/时间)对列进行排序:Mottie jQuery Tablesorter fork自定义排序仅对一个方向进行排序,jquery,parsing,sorting,fork,tablesorter,Jquery,Parsing,Sorting,Fork,Tablesorter,我看到另一个人也有同样的问题,但原因不同 我使用jQuery Tablesorter()的fork,通过使用数据属性的自定义解析器(法语日期/时间)对列进行排序: <td data-since="28-09-2012 15:41:10"> <strong>4 jours, 16 minutes</strong> (28-09-2012 15:41:10) </td> 你知道怎么解决这个问题吗 非常感谢 编辑: 我认为插件确实试图排序,但结
<td data-since="28-09-2012 15:41:10">
<strong>4 jours, 16 minutes</strong> (28-09-2012 15:41:10)
</td>
你知道怎么解决这个问题吗
非常感谢
编辑:
我认为插件确实试图排序,但结果是一样的
以下是插件的调试:
- 第一类,成功:
- 第二种排序,排序中没有更改:
已完成应用小部件(0ms)我终于找到了解决方案 有两个粗略的错误:
- 我告诉插件,索引列3具有解析器“parseSinceColumn”,因此“is”函数应该返回false。事实上,单元格的内容无法与正则表达式匹配,因为“s”不是数据属性的内容,因此插件无法检测到该列的良好解析器
- format函数使用“s”参数来解析日期。好的变量是cellDate
$(document).ready(function() {
//http://stackoverflow.com/questions/9550354/jquery-tablesorter-plugin-secondary-hidden-sorting
$.tablesorter.addParser({
// set a unique id
id: 'parseSinceColumn',
is: function(s) {
return false;
},
format: function(s, table, cell, cellIndex) {
var cellDate = $(cell).attr('data-since');
// get data attributes from $(cell).attr('data-something');
// check specific column using cellIndex
cellDate = cellDate.replace(/\-/g," ");
cellDate = cellDate.replace(/:/g," ");
cellDate = cellDate.split(" ");
return new Date(cellDate[2], cellDate[1]-1, cellDate[0], cellDate[3], cellDate[4], cellDate[5]).getTime();
},
// set type, either numeric or text
type: 'numeric'
});
$("#pr-table").tablesorter({
headers : {
3 : { sorter: 'parseSinceColumn' }
}
});
});
我终于找到了解决办法 有两个粗略的错误:
- 我告诉插件,索引列3具有解析器“parseSinceColumn”,因此“is”函数应该返回false。事实上,单元格的内容无法与正则表达式匹配,因为“s”不是数据属性的内容,因此插件无法检测到该列的良好解析器
- format函数使用“s”参数来解析日期。好的变量是cellDate
$(document).ready(function() {
//http://stackoverflow.com/questions/9550354/jquery-tablesorter-plugin-secondary-hidden-sorting
$.tablesorter.addParser({
// set a unique id
id: 'parseSinceColumn',
is: function(s) {
return false;
},
format: function(s, table, cell, cellIndex) {
var cellDate = $(cell).attr('data-since');
// get data attributes from $(cell).attr('data-something');
// check specific column using cellIndex
cellDate = cellDate.replace(/\-/g," ");
cellDate = cellDate.replace(/:/g," ");
cellDate = cellDate.split(" ");
return new Date(cellDate[2], cellDate[1]-1, cellDate[0], cellDate[3], cellDate[4], cellDate[5]).getTime();
},
// set type, either numeric or text
type: 'numeric'
});
$("#pr-table").tablesorter({
headers : {
3 : { sorter: 'parseSinceColumn' }
}
});
});