I am using the tablesorter plugin and need to sort a column which contains dates and times. Using the shortDate type, the column sorts on date, but not on time i.e. Jan. 12, 2011 11:13 AM goes to the top of the table followed by Jan. 12, 2011 11:16 AM which should be the top placed item. It looks as if the sorting is on text and not on the date. I have tried using a custom parser as suggested on these pages but it didn't work. Can anyone suggest an example format for the date-times as written to screen in the table in order for a custom parser to successfully sort on date and time?
Here is the sql to format the date:
date_format(data_invio,'%b. %e, %Y %l:%i %p')
This is code (found on this site) that I tried for the custom parser:
$.tablesorter.addParser({
id: 'dateMS',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
var d = Date.parse(s);
if (isNaN(d)) {
return -1;
}
return d;
},
// set type, either numeric or text
type: 'numeric'
});
$("table#ElencoRicevuti")
.tablesorter({
dateFormat: 'YYYY-mm-dd HH:ii:ss',
headers:
{
0: {sorter: 'dateMS'},
4: {sorter: false}
}
})
开发者_运维知识库
I love jQuery and all that, but I haven't found a jQuery table sort plugin that works as good as kryogenixs storttable. http://www.kryogenix.org/code/browser/sorttable/.
And the tablesortter plugin you are using hasn't been updated since 2008-03-17
The kryogenix has all sorts of custom sorts. See "Using custom date formats": http://www.kryogenix.org/code/browser/sorttable/#dates
精彩评论