Optimization for european date sorting

Optimization for european date sorting

F2000F2000 Posts: 6Questions: 0Answers: 0
edited February 2012 in General
Hi,

Here is an optimization for the methods writed by Ronan Guilloux (http://www.datatables.net/plug-ins/sorting).

[code]
function format_date(european_date) {
// For dates as "dd/mm/YYYY hh:ii:ss"

// First trim the date
trimed_date = european_date.replace(/^\s+/g, '').replace(/\s+$/g, '');

// Then transform it to an integer
if (trimed_date != '') {
var frDatea = trimed_date.split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');

return (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
}else return 10000000000000; // = l'an 1000 ...
}

jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(x, y) {
x = format_date(x);
y = format_date(y);

return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(x, y) {
x = format_date(x);
y = format_date(y);

return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Nice one - thanks!

    I think I need to spend a bit of time cleaning up the sorting plug-ins and categorising them a bit. I'll be sure to update the plug-in with your modifications. Is there a name / link you would like for the credit, or just F2000? :-)

    Allan
This discussion has been closed.