Date sorting problem with jQuery Tablesorter

前端 未结 7 1402
孤街浪徒
孤街浪徒 2020-11-29 03:21

I am trying to sort a table which has column like 2009-12-17 23:59:59.0. I am using below to apply sort

$(document).ready(function() { 
    $(\         


        
7条回答
  •  臣服心动
    2020-11-29 03:23

    If you are using date/time format like mm/dd/yyyy hh:mm then use below

    $.tablesorter.addParser({ 
            id: "customDate",
            is: function(s) {
                //return false;
                //use the above line if you don't want table sorter to auto detected this parser                        
                //21/04/2010 03:54 is the used date/time format 
                return /\d{1,2}\/\d{1,2}\/\d{1,4} \d{1,2}:\d{1,2}/.test(s);
            },
            format: function(s) {
                s = s.replace(/\-/g," ");
                s = s.replace(/:/g," ");
                s = s.replace(/\./g," ");
                s = s.replace(/\//g," ");
                s = s.split(" ");                       
                return $.tablesorter.formatFloat(new Date(s[2], s[1]-1, s[0], s[3], s[4]).getTime());                                         
            },
            type: "numeric"} );
    

提交回复
热议问题