Hi All!
I am using DataTables and the issue I am having is for my date columns I am using mm/dd/yyyy hh:mm am/pm format and when I click on date column to sort, DataTables changes have correctly working for ascending order and not not for decending order. Is there some code I can put in to correct this issue?
I am writing custom sorting for ascending and decending.Can any one help to correct my code in decending sort?
My code:
jQuery.fn.dataTableExt.oSort['NUMasset-asc'] = function(a,b) {
var aSplit = a.substring(a.indexOf(">")+1,a.lastIndexOf("</"));
var bSplit = b.substring(b.indexOf(">")+1,b.lastIndexOf("</"));
var aNum = parseInt(aSplit);
var bNum = parseInt(bSplit);
return (aNum < bNum) ? -1 : ((aNum > bNum) ? 1 : 0);
};
jQuery.fn.dataTableExt.oSort['NUMasset-desc'] = function(a,b) {
var aSplit = a.substring(a.indexOf(">")+1,a.lastIndexOf("</"));
var bSplit = b.substring(b.indexOf(">")+1,b.lastIndexOf("</"));
var aNum = parseInt(aSplit);
var bNum = parseInt(bSplit);
return (aNum < bNum) ? 1 : ((aNum > bNum) ? -1 : 0);
};
$(document).ready(function() {
$('#dt').dataTable({
"iDisplayLength": 20,
"bPaginate": true,
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "asc" ]],
"bLengthChange": false,
"bInfo": true,
"aoColumns": [
{ "sType": "NUMasset" },
null,
null,
null,
null,
null,
null
]
});
} );
My Output:(wrong behaviour output in decending order)
Date / Time
6/5/2013 9:45 AM
5/1/2013 11:00 AM
5/8/2013 10:00 AM
4/15/2013 9:30 AM
4/18/2013 1:15 PM
3/30/2013 2:00 PM
Thanks,
I am using DataTables and the issue I am having is for my date columns I am using mm/dd/yyyy hh:mm am/pm format and when I click on date column to sort, DataTables changes have correctly working for ascending order and not not for decending order. Is there some code I can put in to correct this issue?
I am writing custom sorting for ascending and decending.Can any one help to correct my code in decending sort?
My code:
jQuery.fn.dataTableExt.oSort['NUMasset-asc'] = function(a,b) {
var aSplit = a.substring(a.indexOf(">")+1,a.lastIndexOf("</"));
var bSplit = b.substring(b.indexOf(">")+1,b.lastIndexOf("</"));
var aNum = parseInt(aSplit);
var bNum = parseInt(bSplit);
return (aNum < bNum) ? -1 : ((aNum > bNum) ? 1 : 0);
};
jQuery.fn.dataTableExt.oSort['NUMasset-desc'] = function(a,b) {
var aSplit = a.substring(a.indexOf(">")+1,a.lastIndexOf("</"));
var bSplit = b.substring(b.indexOf(">")+1,b.lastIndexOf("</"));
var aNum = parseInt(aSplit);
var bNum = parseInt(bSplit);
return (aNum < bNum) ? 1 : ((aNum > bNum) ? -1 : 0);
};
$(document).ready(function() {
$('#dt').dataTable({
"iDisplayLength": 20,
"bPaginate": true,
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "asc" ]],
"bLengthChange": false,
"bInfo": true,
"aoColumns": [
{ "sType": "NUMasset" },
null,
null,
null,
null,
null,
null
]
});
} );
My Output:(wrong behaviour output in decending order)
Date / Time
6/5/2013 9:45 AM
5/1/2013 11:00 AM
5/8/2013 10:00 AM
4/15/2013 9:30 AM
4/18/2013 1:15 PM
3/30/2013 2:00 PM
Thanks,