Can you disable sorting on the datatable but also have a default ordering for the first column?
Can you disable sorting on the datatable but also have a default ordering for the first column?
Im trying to order my datatable by first name (first column) and i am only able to do if sorting isnt disabled for the table.
This scenario 100% requires that the table must not be sortable by the user, but does this also mean that i cant apply a default order on the first column?
I have tried this but obviously this alone allows sorting by the user
{
order: [[0, "asc"]]
}
So i then tried this but this doesnt order the first column
{
order: [[0, "asc"]],
bSort: false,
}
So i then tried this but again it did not work
{
bSort: false,
columnDefs: [
{
targets: [0, 1], //first name & last name
orderable: true
},
{
targets: [ 0 ],
orderData: [ 0, 1 ]
},
{
targets: [ 1 ],
orderData: [ 1, 0 ]
}
]
}
I know i can specify ordering for each column but this table is a dynamic table and there is a varying number of columns depending on the user. It could have 3 columns or it could have 15 so this is not applicable to my scenario.
Any help is massively appreciated. Thanks!
This question has an accepted answers - jump to answer
Answers
That is global. You need to remove that, to allow ordering to happen at all.
Then use the
columns.orderable
option to disable user ordering of the columns.Allan
Thanks but doesn't this mean that, although the table is now ordered by first name, the user can sort the later columns. Which is what i don't want.
I want to disable sorting and order by firstname
This config will disable the ability of the user to sort any column:
To allow Datatables to initially sort the data you need to remove
bSort: false,
from the config.Kevin
Thanks it worked!