Reputation: 157
What I am trying to do a secondary sort of column 1, if the 13th column is hit on a page but not interrupt the functioning of any other clicked on column.
This is the jQuery DataTable code
$('#table-report').dataTable({
"aLengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
"iDisplayLength": 10,
"bFilter": true,
"bInfo": false,
"sEmptyTable": "No data returned for values input.",
"sDom": '<top>l',
"sPaginationType": "full_numbers",
"bJQueryUI": false,
"aoColumnDefs":
[
{ 'bSortable': true, "aTargets": [0, 17] },
{ "sType": "time-us", "aTargets": [16] }
],
"oLanguage": {
"sLengthMenu": "View Per Page _MENU_ ",
"sSearch": "Search all columns:"
}
});
This closest I have gotten is adding
{ targets: [13], orderData: [13, 1] }
to "aoColumnDefs"
. The problem is that the sort (which happens correctly - Primarily and Secondarily) happens on page load and disables the ability to sort by any other column.
Does someone know how I can alter what I have to do the secondary sort only when the 13th column header is clicked on, while not disabling the ability of sorting by any other column by clicking the appropriate column headers?
Upvotes: 2
Views: 893
Reputation: 157
I finally got it....
I ended up adding an id to the Route column header and calling fnsort
manually on click:
$('#dataTableId').fnSort([[13, 'asc'], [1, 'asc']])
Upvotes: 0
Reputation: 122
It looks like your using an older version of Datatables (1.9?) by the looks of your definition namings
Try something like this for the 1.9:
"aaSorting": [ [13,'asc'], [1,'asc'] ]"
Alternatively updating to 1.10 would give your code the option you tried a better chance to run without crashing. Allen (maker of Datatables) was quite good on backwards compatibility
Upvotes: 1