0

无法使用 jQuery 表格排序器对日期模式 'yyyy-MM-dd hh:mm:ss.SSS' 进行排序。我也尝试了以下解析器

ts.addParser({
    id: "customDate",
    is: function (s) {
        //return false;
        //use the above line if you don't want table sorter to auto detected this parser                           //else use the below line.           
        //attention: doesn't check for invalid stuff            
        //2009-77-77 77:77:77.000 would also be matched            
        //if that doesn't suit you alter the regex to be more restrictive           
        return /\d{1,4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}.\d{1,3}/.test(s);
    },
    format: function (s) {
        s = s.replace(/\-/g, " ");
        s = s.replace(/:/g, " ");
        s = s.replace(/\./g, " ");
        s = s.split(" ");
        return $.tablesorter.formatFloat(new Date(s[0], s[1] - 1, s[2], s[3], s[4], s[5], s[6]).getTime() + parseInt(s[7]));
    },
    type: "numeric"
});

提前致谢。

4

1 回答 1

0

答案已经在此可用

请注意,您需要将自定义排序器添加到 local.js 文件以使表格排序器正常工作:

$(function() {
    $("table").tablesorter({
        headers: {
            6: { sorter:'customDate' }
        }
    });
});
于 2013-11-27T12:26:21.320 回答