Orderable false on target 0 (first col) not working until another column is sorted.
Orderable false on target 0 (first col) not working until another column is sorted.
I'm using this code to remove sorting / ordering from the first column 0, the column still receives the class sorting_asc, only after I click a column header or 3 4 or higher does the class disappear and it becomes sorting_disabled
however when the page loads targets 1 and 2 are already set to sorting_disabled
. I only need to disable column 0, but added 1, and 2 as a test which is weird because they load with sorting disabled right away. What is causing column 0 to have sorting enabled until the table is redrawn after another column is sorted?
columnDefs: [
{ orderable: false, targets: [0,1,2] },
{ visible: false, targets: [5,12,13] }
]
This question has an accepted answers - jump to answer
Answers
Hi anag. I'm having the exact same issue, except I'm using the "columns" array rather than "columnDefs". The first column shows a sorting arrow until I sort the table on another column, even though I have set the first column with orderable:false. Did you ever find a resolution on this.
In case anyone else is having the same issue:
After some more research, it looks like this is actually intended behavior because the table is by default sorted on the first column. So the indicator is there to show you that the table is sorted on that column. In order to remove the indicator, you need to tell the table to default sort on a different column, or no column at all. In my case, I want my table sorted the same way the data is sent from the server, so I just passed in "order":[] as an option to the table, to disable the default sort. This fixed my problem. Here's the post to the github issue where I found the solution: https://github.com/DataTables/DataTables/issues/339
Hi Flying, Anag
I've had the same issue and have the following code which has resolved the issue for me.
So:
order: [[1,desc]] sets the default order to desc on the second column (column 1) and { orderable: false, width: "8%" }, removes the ordering on the first column (column 0). Without the first bit the table is ordered on load by column 0
Hope that makes sense
Steve