I need to sort a column by weekdays (mon, tue, wed, thu, fri, sat, sun) and cannot seem to get this working. Note that I am using the latest 1.10 version of datatables.
This is located along with other extensions in its own file and called after jquery.dataTables.js is loaded, but before the table initialization.
/* custom sorting by weekday */
$.extend( $.fn.dataTableExt.oSort, {
"weekday-pre": function ( a ) {
return $.inArray( a, ["SUN","MON","TUE","WED","THU","FRI","SAT"] );
},
"weekday-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"weekday-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
then in my table initialization I specify the sort for this particular column. Values can/will only be "SUN","MON","TUE","WED","THU","FRI","SAT" coming from the database.
"columns": [
..... some column entries,
{
"data": "day",
"type": "weekday"
},
..... the rest of the column entries
No errors in the console, however, sorting just defaults to the regular alphabetical sorting when I sort by clicking on the column title.