I'm currently attempting to organize a column in a table using the DataTables plugin that contains UK date and time formats such as: 21/09/2013 11:15
Implementing Ronan Guilloux's code:
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"uk_date-pre": function ( a ) {
if ($.trim(a) != '') {
var frDatea = $.trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
} else {
var x = 10000000000000; // = the year 1000 ...
}
return x;
},
"uk_date-asc": function ( a, b ) {
return a - b;
},
"uk_date-desc": function ( a, b ) {
return b - a;
}
} );
In addition, I have included this code to automatically detect the format so that manual setting of the column is not required:
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/(0[1-9]|[12]\d|3[0-2])\/(0[1-9]|1[0-2])\/\d{4} (0[1-9]|1\d|2[0-3]):(0[1-9]|[1-5]\d)$/))
{
//console.log(sData);
return 'uk_date';
}
return null;
}
);
My issue arises from the fact that even though the regex successfully matches the string, it does not trigger the 'uk_date-pre', 'uk_date-asc', or 'uk_date-desc'. Can anyone provide insight as to why this might not be functioning?