i want to sort date but date column sorting on string where to set type:date in my code
i want to sort date but date column sorting on string where to set type:date in my code
Propix_311
Posts: 5Questions: 2Answers: 0
$.extend( _ext.type.order, {
// Dates
"date-pre": function (d) {
return Datetime.parse(d) || 0;
//"date-pre": function ( a ) {
// var ukDatea = a.split('/');
// return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
},
"date-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
},
// html
"html-pre": function ( a ) {
return _empty(a) ?
'' :
a.replace ?
a.replace( /<.*?>/g, "" ).toLowerCase() :
a+'';
},
// string
"string-pre": function ( a ) {
// This is a little complex, but faster than always calling toString,
// http://jsperf.com/tostring-v-check
return _empty(a) ?
'' :
typeof a === 'string' ?
a.toLowerCase() :
! a.toString ?
'' :
a.toString();
},
// string-asc and -desc are retained only for compatibility with the old
// sort methods
"string-asc": function ( x, y ) {
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
},
"string-desc": function ( x, y ) {
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
}
});
This discussion has been closed.
Answers
use the ultimate date / time sorting plugin with moment.js please:
https://datatables.net/plug-ins/sorting/datetime-moment
https://datatables.net/blog/2014-12-18
And here is more on international sorting (including dates):
https://stackoverflow.com/questions/53238318/html5-javascript-datatables-order-sort-of-columns
https://datatables.net/forums/discussion/comment/172741/#Comment_172741