2 回答
TA贡献1833条经验 获得超4个赞
如果有人偶然发现这种特定的日期格式,我就找到了解决方案。事实证明,TableSorter 插件允许添加自定义解析器,您可以满足自己的需要。关于这里的更多信息 - https://mottie.github.io/tablesorter/docs/example-parsers.html。
在这种特定情况下,它看起来像这样,现在可以工作并且该列是可排序的:
$.tablesorter.addParser({
id: 'custom_date_parser',
// Auto-detection
is: function(date) {
return false;
},
// Normalize data and allow sorting for this specific type
format: function(date) {
// get current year
var current_year = new Date().getFullYear()
// obtain date values from column
// current format HH:mm, dd.MM
var hour = date.slice(0, 2);
var minutes = date.slice(3, 5);
var day = date.slice(7, 9);
var month = date.slice(10, 12);
// convert to date object
return date = new Date(current_year, month - 1, day, hour - 1, minutes)
},
parsed: false,
// Type of sorting to use
type: 'numeric'
});
// Perform the sorting
$("#table-name").tablesorter({
// apply custom parser only to the second column
headers: {
1: {
sorter: 'custom_date_parser'
}
}
});
TA贡献1744条经验 获得超4个赞
该dateFormat选项仅允许 3 个设置:("mmddyyyy"默认)"ddmmyyyy"和"yyyymmdd".
在这种情况下,您需要添加一个自定义列解析器- 请参阅此演示,但它只有一个用于 Sugar.js 库的示例。
特别是,确保加载和使用这个包含 Sugar.js 和 Date.js 库接口的解析器。
添加回答
举报
