I have a datatable I'm using which has 5 columns ( http://datatables.net/ )
The columns are
- Date in format of: Jan 5
- Time in format of: 10:31 AM (xx:xx XX)
- Columns 3, 4, 5 aren't important, they're just data that I dont care about the sorting as long as 1 & 2 are correct.
I want to sort by Date FIRST (most recent), then I want to sort by Time (most recent at top).
So Jan 5, 4:58 PM should show before 4:58 AM, and obviously all the other numbers need to work as well for all other times. The format is always the same, ie: 12:34 AM, 4:15 PM, 12:00 AM, etc.
For the date, that already works perfectly. There's only 2 days of data max in the datatable, so even when it rolls over to the 1st of the month, that will still show at the top which is fine. I have looked at the documentation and I'm confused how to do the correct sorting for my Time column.
Here is my code:
oTable = $('#posts').dataTable({
"bSort": true,
"aaSorting": [ [0,'desc'], [1,'asc'] ],
"aoColumns": [
null,
{ "sType": 'time-sort' },
null,
null,
null
]
});
This is from here: http://datatables.net/release-datatables/examples/basic_init/multi_col_sort.html
I take it now I have to build some sort of custom sorting algorithm for time using the sType property for "aoColumns" (you can see it in the example link above where he sorts case sensitively), and I have zero idea how to do this :( I'm not quite even sure if I did this right so far. It seems to sort the two columns fine, but now I need to make it so time is proper...
Here is the other part of the code that I believe I need. (once again, this is from the example). I'm 99% sure this is where I need to put in my custom time sorting code for both ascending and decending.
/* Define two custom functions (asc and desc) for time sorting */
jQuery.fn.dataTableExt.oSort['time-sort-asc'] = function(x,y) {
return ???;
};
jQuery.fn.dataTableExt.oSort['time-sort-desc'] = function(x,y) {
return ???
};