2010-04-14 44 views
2

我试图理清其中有像列04月01日表2010年我使用下面的链接申请排序排序上被格式化的日期的jQuery

$(document).ready(function() 
{ 
    $("#dataTable").tablesorter(); 
}); 

但它不工作的格式DD MMM YY的日期。任何人都可以建议我如何应用这种格式进行排序?

回答

1

查看example parsers page,它向您展示了如何创建自定义分析器。你可以使用new Date(date)Date.parse(date)解析日期。我没有测试它的手段,但这样的事情应该工作:

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'ddMMMyy', 
    is: function(s) { 
     // return false so this parser is not auto detected 
     return false; 
    }, 
    format: function(s) { 
     // parse the string as a date and return it as a number 
     return +new Date(s); 
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

为你做所有剩下的就是使用headers选项指定排序方法:

$(document).ready(function() { 
    $("dataTable").tablesorter({ 
     headers: { 
      6: { // <-- replace 6 with the zero-based index of your column 
       sorter:'ddMMMyy' 
      } 
     } 
    }); 
});