TimeFormat(HH:MM tt) column sorting

TimeFormat(HH:MM tt) column sorting

gurusudhakargurusudhakar Posts: 6Questions: 0Answers: 0
edited December 2011 in DataTables 1.9
Hi,

One of the columns in my datatable consist startTime(hh:mm pm) and endTime(hh:mm am) Please adivce how to sort timeFormat.
Kindly let me know if any mechanism that we already have?

I was trying to figure out in this way but its not sorting correctly, my code is below.
// sorting of time in "hh:mm tt" format in ascending order*/
jQuery.fn.dataTableExt.oSort['time-custom-asc'] = function(a,b) {
// Making sure to remove any HTML code sorrounding the value to be sorted.
var stime = a.replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
var etime = b.replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
var timeTokens1 = stime.split(' ');
var timeTokens2 = etime.split(' ');
var x = (timeTokens1[0] + getIdx(timeTokens1[1])) * 1;
var y = (timeTokens2[0] + getIdx(timeTokens2[1])) * 1;

return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

//sorting of time in "hh:mm tt" format in descending order*/
jQuery.fn.dataTableExt.oSort['time-custom-desc'] = function(a,b) {
// Making sure to remove any HTML code sorrounding the value to be sorted.
var stime = a.replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
var etime = b.replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
var timeTokens1 = stime.split(' ');
var timeTokens2 = etime.split(' ');
var x = (timeTokens1[0] + getIdx(timeTokens1[1])) * 1;
var y = (timeTokens2[0] + getIdx(timeTokens2[1])) * 1;

return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
Thanks,
Gs
This discussion has been closed.