JQuery Table Sorter 在日期模式上失败'yyyy-MM-dd hh:mm:ss.SSS'



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

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"
});

提前谢谢。

答案已经有了

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

$(function() {
    $("table").tablesorter({
        headers: {
            6: { sorter:'customDate' }
        }
    });
});

相关内容

最新更新