0
A
回答
0
第一個問題是將日期文本解析爲javascript Date object
將識別的格式。一旦轉換爲日期,插件會將日期視爲數字排序類型。這是您的格式的工作解析器。
DEMO:http://jsfiddle.net/H9u7C/1/
$.tablesorter.addParser({
// set a unique id
id: 'changeToDate',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
var a = $.trim(s).split(' ');
var time = a[0];
var dateParts = a[1].split('/');
var dateText = [dateParts[1], dateParts[0], dateParts[2]].join('/') + ' ' + time;
var dateObj = new Date(dateText);
return dateObj;
},
type: 'numeric'
});
用法如下概述了自定義分析器演示的插件網站
0
我有2.0的tablesorter同樣的問題。 日期DD/MM/YY是錯的線982 ...
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3");
是錯誤的,正確的是
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$3/$2/$1");
我ts.addParser({ID: 「shortDate」 ...是:
ts.addParser({
id: "shortDate",
is: function (s) {
return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
}, format: function (s, table) {
var c = table.config;
s = s.replace(/\-/g, "/");
if (c.dateFormat == "us") {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
} else if (c.dateFormat == "uk") {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
} else if (c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") {
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$3/$2/$1");
} else if (c.dateFormat == "dd/mm/yyyy" || c.dateFormat == "dd-mm-yyyy") {
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
}
return $.tablesorter.formatFloat(new Date(s).getTime());
}, type: "numeric"
});
我有加DD/MM/YYYY情況下,對於日期,我不知道... :(
你必須把日期格式:「DD/MM/Y yyy「作爲參數。
相關問題
- 1. 與jquery tablesorter排序日期的問題
- 2. 使用jQuery tablesorter排序長日期
- 3. 使用jQuery tablesorter排序mm/yy日期
- 4. 日期使用jquery tablesorter排序問題
- 5. jQuery tablesorter自定義日期格式
- 6. 與Tablesorter排序日期
- 7. jquery tablesorter自定義日期
- 8. 如何使用jquery tablesorter對mm/yy格式的日期進行排序?
- 9. jQuery Tablesorter日期選擇器
- 10. tablesorter:按unix秒排序,但按特定日期格式顯示
- 11. 使用帶intitalsortorder的日期格式時Tablesorter排序問題
- 12. 的tablesorter日期DD.MM.YYYY
- 13. 排序日期字段與tablesorter
- 14. jquery tablesorter複雜日期的addParser
- 15. 的jQuery的tablesorter排序日期DD MMM YYYY
- 16. jQuery Tablesorter沒有以日期結尾的排序字段
- 17. 使用相對日期的Tablesorter排序表列
- 18. 針對不同日期格式的Jquery tablesorter
- 19. jQuery tablesorter與多個div的排序列
- 20. jQuery Tablesorter排序
- 21. 的jQuery的tablesorter不排序
- 22. tablesorter過濾日期格式dd-mm-yyyy
- 23. 可用Jquery Tablesorter排序的HTML表格?
- 24. 排除列使用jQuery tablesorter排序
- 25. 日期時間jQuery tablesorter解析器MM.DD.YYYY HH:MI AM格式
- 26. jQuery Tablesorter不排序列
- 27. 如何使用tablesorter jquery插件對字符串和日期進行排序?
- 28. JQuery tablesorter Ajax排序
- 29. 如何使用javascript排序日期對象tablesorter?
- 30. 使用jQuery tablesorter進行列排序
這裏是插件網站:http://tablesorter.com/docs/ – Ran
插件文檔展示瞭如何創建自定義排序解析器 – charlietfl
以及如何爲日期創建這種自定義排序解析器? – Ran