2014-09-03 137 views
1

我想排序表中具有类似“yyyy-mm-dd hh:mm:ss S:更多字符串”数据的列中的列。 该数据是字符串。我使用jquery.tablesorter 2.0根据日期进行排序。我无法对其进行分类。你能帮帮...使用jQuery tablesorter进行列排序

艾米

回答

1

你需要使用工作date-extract parsers available here之一,它here is a demo

$.tablesorter.addParser({ 
    id: "extractYYYYMMDD", 
    is: function (s) { 
     // don't auto detect this parser 
     return false; 
    }, 
    format: function (s, table) { 
     var date = s.replace(/\s+/g, " ").replace(/[\-.,]/g, "/").match(/(\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i); 
     if (date) { 
      date = date[0].replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/, "$2/$3/$1"); 
      return $.tablesorter.formatFloat((new Date(date).getTime() || ''), table) || s; 
     } 
     return s; 
    }, 
    type: "numeric" 
}); 

$('table').tablesorter({ 
    theme: 'blackice', 
    headers: { 
     1: { 
      sorter: 'extractYYYYMMDD' 
     } 
    }, 
    widgets: ['zebra', 'columns'] 
}); 
+0

嗨,真棒......重要的指导意义。 – 2014-09-04 04:43:13

相关问题