I just cannot get any sorting plugins to work at all.
I just cannot get any sorting plugins to work at all.
I am trying to sort a dd/mm/yyyy date column, which I can see is a popular thing. Nothing works. What am I doing wrong?
[code]
/**
* This is the plugin code I found somewhere. Will move to a new file when I see it works.
*/
$.fn.dataTableExt.oSort['date-asc'] = function(a,b) {
var x = Date.parse(a);
var y = Date.parse(b);
if (x == y) { return 0; }
if (isNaN(x) || x < y) { return 1; }
if (isNaN(y) || x > y) { return -1; }
};
$.fn.dataTableExt.oSort['date-desc'] = function(a,b) {
var x = Date.parse(a);
var y = Date.parse(b);
if (x == y) { return 0; }
if (isNaN(y) || x < y) { return -1; }
if (isNaN(x) || x > y) { return 1; }
};
$(document).ready(function() {
/**
* Set up data table
*/
$('#orders table').dataTable({
'oLanguage': eval(window.app.DATA_TABLES_CONFIG),
'sPaginationType': 'full_numbers',
'aaSorting': [[0, 'desc']],
'aoColumns': [null, null, null, {'sType': 'date'}]
});
});[/code]
[code]
/**
* This is the plugin code I found somewhere. Will move to a new file when I see it works.
*/
$.fn.dataTableExt.oSort['date-asc'] = function(a,b) {
var x = Date.parse(a);
var y = Date.parse(b);
if (x == y) { return 0; }
if (isNaN(x) || x < y) { return 1; }
if (isNaN(y) || x > y) { return -1; }
};
$.fn.dataTableExt.oSort['date-desc'] = function(a,b) {
var x = Date.parse(a);
var y = Date.parse(b);
if (x == y) { return 0; }
if (isNaN(y) || x < y) { return -1; }
if (isNaN(x) || x > y) { return 1; }
};
$(document).ready(function() {
/**
* Set up data table
*/
$('#orders table').dataTable({
'oLanguage': eval(window.app.DATA_TABLES_CONFIG),
'sPaginationType': 'full_numbers',
'aaSorting': [[0, 'desc']],
'aoColumns': [null, null, null, {'sType': 'date'}]
});
});[/code]
This discussion has been closed.
Replies
Allan
Edit: It's OK. I got it to work. I think the problem was that my plugin code was wrapped in
[code](function ($) {
// ...
}(jQuery));[/code]
No, because Date.parse expects the American MM/DD/YYYY format...
You want this plug-in: http://datatables.net/plug-ins/sorting#date_uk
Allan