Fix for "UK Date" sorting plugin
Fix for "UK Date" sorting plugin
PaoloValladolid
Posts: 35Questions: 0Answers: 0
The plugin code works mostly fine off the bat . My respect goes to Andy McMaster for submitting it to the Datatables.net website.
However, it was putting 11/08/2005 before 09/13/2005 in ascending order, because the code was calculating a higher value for the latter date. Here is my fix, which is to multiply the month portion by 2 so that it is weighted higher:
[code]
jQuery.fn.dataTableExt.oSort['us_date-asc'] = function(a,b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]*2) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]*2) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['us_date-desc'] = function(a,b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]*2) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]*2) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
However, it was putting 11/08/2005 before 09/13/2005 in ascending order, because the code was calculating a higher value for the latter date. Here is my fix, which is to multiply the month portion by 2 so that it is weighted higher:
[code]
jQuery.fn.dataTableExt.oSort['us_date-asc'] = function(a,b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]*2) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]*2) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['us_date-desc'] = function(a,b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]*2) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]*2) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
This discussion has been closed.