Need help desc order is not working in sorting
Need help desc order is not working in sorting
I tried following code to make numbers like '100-1001', '100-11' to short properly but descending code is not working at all. Please help
j$.fn.dataTable.ext.type.order['intParse-desc'] = function ( x, y ) {
var a= parseInt(x.replace("-", ""));
var b= parseInt(y.replace("-", ""));
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
};
j$.fn.dataTable.ext.type.order['intParse-asc'] = function ( x, y ) {
var a= parseInt(x.replace("-", ""));
var b= parseInt(y.replace("-", ""));
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
};
ticketTable = j$('[id$="ticketTable"]').DataTable({
columnDefs: [{ type: 'intParse', targets: 0 }]
});
Replies
Neither it is working following way
j$.extend( jQuery.fn.dataTableExt.oSort, {
"intParse-asc": function ( x, y ) {
a= parseInt(x.replace("-", ""));
b= parseInt(y.replace("-", ""));
return -((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"intParse-desc": function ( x, y ) {
a= parseInt(x.replace("-", ""));
b= parseInt(y.replace("-", ""));
return -((a < b) ? 1 : ((a > b) ? -1 : 0));
}
Since it is not actually a number, why do you not just sort it as a string?
No string will not work as client is looking it as number.
Like
100-11
100-20
100-100
100-102
It should short like this
You'd need to write an ordering plug-in that will sort your data as you require since that isn't strictly numeric only data.
Another option might be to use the natural sorting plug-in.
Allan
Thanks @allan it worked for me natural sorting plug-in