Date (dd/mm/YYYY hh:ii:ss)
Sort date / time in the format dd/mm/YYYY hh:ii:ss
- Author: Ronan Guilloux
- Deprecated: This plug-in has been deprecated and replaced with other functionality. Please see the detailed description below for more information.
This plug-in will provide date sorting for the "dd/mm/YYYY hh:ii:ss" formatting, which is common in France and other European countries. It can also be quickly adapted for other formatting as required. Furthermore, this date sorting plug-in allows for empty values in the column.
Please note that this plug-in is **deprecated*. The datetime plug-in provides enhanced functionality and flexibility.
Plug-in code
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-euro-pre": function ( a ) {
var x;
if ( a.trim() !== '' ) {
var frDatea = a.trim().split(' ');
var frTimea = (undefined != frDatea[1]) ? frDatea[1].split(':') : [00,00,00];
var frDatea2 = frDatea[0].split('/');
x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + ((undefined != frTimea[2]) ? frTimea[2] : 0)) * 1;
}
else {
x = Infinity;
}
return x;
},
"date-euro-asc": function ( a, b ) {
return a - b;
},
"date-euro-desc": function ( a, b ) {
return b - a;
}
} );
CDN
This plug-in is available on the DataTables CDN:
Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.
Version control
If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!
- This plug-in: date-euro.js
- Full DataTables plug-ins repository: DataTables/Plugins
Example
$('#example').dataTable( {
columnDefs: [
{ type: 'date-euro', targets: 0 }
]
} );