Can fnSort use the default ordering (asc vs desc) or does it have to be passed as a parameter?
Can fnSort use the default ordering (asc vs desc) or does it have to be passed as a parameter?
I'm using a syntax like this (where thisCol is the that user clicked on) and it's working fine:
oSearchResultsTable.fnSort( [ [thisCol, 'asc'], [1,'asc'], [2,'asc'] ] );
But I'd like the sort order for thisCol be be asc/desc depending on how many times user clicked, i.e. i'd like to just inherit the default sort order behavior. Is this possible? I'm not sure how to trap what the current sort order is, and pass it as the second parameter. I've tried looking for attributes, like $(this).attr('aria-sort'), but that seems wrong (and won't work). Is there a way to do this strictly through the datatables object without reference to the DOM?
many many thanks.
Jeff
oSearchResultsTable.fnSort( [ [thisCol, 'asc'], [1,'asc'], [2,'asc'] ] );
But I'd like the sort order for thisCol be be asc/desc depending on how many times user clicked, i.e. i'd like to just inherit the default sort order behavior. Is this possible? I'm not sure how to trap what the current sort order is, and pass it as the second parameter. I've tried looking for attributes, like $(this).attr('aria-sort'), but that seems wrong (and won't work). Is there a way to do this strictly through the datatables object without reference to the DOM?
many many thanks.
Jeff
This discussion has been closed.
Replies
Interestingly I was wondering about exactly this yesterday while working on an update in the sorting methods. I decided not to put it in since no one had ever expressed an interest in it before...
I'll take another look and see if it can be done with very little code.
Allan
Jeff
$('#tblRequiresAction th').click(function () {
if ($(this).attr('aria-sort')=='ascending') {
oRequiresActionTable.fnSort( [ [$(this).index(), 'asc'], [1,'asc'], [2,'asc'] ] );
} else {
oRequiresActionTable.fnSort( [ [$(this).index(), 'desc'], [1,'asc'], [2,'asc'] ] );
}
});
Allan
$('#tblSearchResults th, #tblRequiresAction th').click(function () {
var thisCol = $(this).index() ;
var thisColOrder = $(this).attr('aria-sort')==='ascending' ? "asc": "desc" ;
oSearchResultsTable.fnSort( [ [thisCol, thisColOrder], [1, 'asc'], [2, 'asc'] ] );
});
I looked at the fnSortListener page, but I'm not clear on how the listener would toggle ascending/descending. Is there an example of that somewhere?
I haven't been able to reproduce the problem with the aria attribute not updating when using fnSort - it appears to work as it should for me.
I should say that 1.10 is going to have an API to get the current sort state, rather than needing to resort to methods like that :-)
Allan