I have a jQuery datatable with date and time columns:
Date Time Note
1/2/2015 10:02:03 Test
1/4/2915 02:12:32 Test
1/3/2015 02:05:03 Test
3/2/2015 11:02:03 Test
1/4/2015 01:02:13 Test
I want to implement a sort for time. When sorting on time, we first need to sort on date, then time:
Date Time Note
1/2/2015 10:02:03 Test
1/3/2015 02:05:03 Test
1/4/2015 01:02:13 Test
1/4/2915 02:12:32 Test
3/2/2015 11:02:03 Test
I have the following code:
//jQuery datatable code
{ mData: 'date', sTitle: 'Date', sClass: "dtDate" },
{ mData: 'time', sTitle: 'Time', sClass: "dtTime", sType: "time-date-sort"},
{ mData: 'notes', sTitle: 'Notes' },
// More code...
jQuery.fn.dataTableExt.oSort['time-date-sort-asc'] = function(startTime, endTime) {
//Date and time sorts go here
return sortedVal;
};
jQuery.fn.dataTableExt.oSort['time-date-sort-desc'] = function (startTime, endTime) {
//Date and time sorts go here
return sortedVal;
};
I am able to sort on the time using this, but how would I first sort on date? I am trying to figure out how to get a reference of the date value in the table row (associated with the time value in that row). For example, how to I grab the date object 1/2/2015 for the row where time is 10:02:03? It does not appear as if I can add custom parameters to the oSort function. Do I use jQuery.fn.dataTableExt.oSort or is jQuery.fn.dataTableExt.afnSortData a better option for this?