In my project I want to sort date which is in dd-mm-yyyy format. I tried like this below
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function(a) {
var ukDatea = a.split('-');
return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
},
"date-uk-asc": function(a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-uk-desc": function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
But this is not working. Here only date and month is getting sorted not also on the basis of year. I took reference from here Datatable date sorting dd/mm/yyyy issue
I know this is an old question, but in case you've just come here from Google, there is a built in solution now.
Just add an HTML5 attribute to the element:
<td data-th="Lastrun" data-order="[unixTimestamp]">
[myWeirdDateFormat]
</td>
https://datatables.net/examples/advanced_init/html5-data-attributes.html
Well it works for me out of the box but I have less complicated date and times so probably its best if you use this http://datatables.net/plug-ins/sorting/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With