I have a column my users want to sort by that doesn't contain values that are reasonably sortable. The sort order the users want to achieve is rather psycho-logical than logical.
I built a solution that allows the user to click on the sorting symbols in the column header. Subsequently the table is sorted by using values from a hidden column. For the user it feels like the table was sorted using the values from the column she clicked on.
I could only achieve this messing around with jQuery which I don't like. I didn't find anything suitable in the API. Question: Is there anything usable for this purpose in the API?
This is my solution:
The user sees open tasks and can order the contracts by the earliest task due date a contract has. If the contract has several tasks with several due dates the following due dates of that contract are being ignored for sorting.
This is what it looks like. Contracts with at least one overdue task are red.
The column is "Offene Aufgaben" the sorting symbol is "fake" if you will. If the user clicks on it the table is sorted by a hidden column.
HTML: the "Offene Aufgaben" column and the hidden column are marked in yellow.
Column "Weitere Ereignisse" is renamed to "Offene Aufgaben" later - so don't be confused ...
And here is the javascript code. (The data table is used on multiple pages in different configurations. We are on "inboxTasksPage" here. The ids to look for are "furtherEventsCol" and "minTaskDueDate". "furtherEventsCol" Column has "orderable: false" set.
//has to be set on top of the code because the columns will be hidden - then the jquery
//command does not work any longer!
var ixOrder; var descAsc;
if ( inboxTasksPage ) {
ixOrder = $('#minTaskDueDate').index();
descAsc = 'asc';
} else {
ixOrder = $('#updateTime').index();
descAsc = 'desc';
}
......
if ( inboxTasksPage ) {
//first click on OpenTasks causes descending order because the initial order
//is by OpenTasks (furtherEventsCol) ascending
var clickCounter = 0;
//table was ordered initially by column #minTaskDueDate which contains the
//minimum due dates of each contract with open tasks
$('#tblCtrManagement').on( 'click', 'th:not(#furtherEventsCol)', function () {
clickCounter = 1; //next click on OpenTasks will cause ascending order
$('th#furtherEventsCol').addClass('sorting');
$('th#furtherEventsCol').removeClass('sorting_asc sorting_desc');
} );
$('#tblCtrManagement').on( 'click', 'th#furtherEventsCol', function () {
clickCounter++;
$('th#furtherEventsCol').removeClass('sorting sorting_asc sorting_desc');
if ( clickCounter % 2 == 0 ) { //even click number
ctrTable.order([ ixOrder, 'asc' ]).draw();
$('th#furtherEventsCol').addClass('sorting_asc');
} else { //odd click number
ctrTable.order([ ixOrder, 'desc' ]).draw();
$('th#furtherEventsCol').addClass('sorting_desc');
}
} );
}