Hide the sorting option on all but one column?
Hide the sorting option on all but one column?
richardk1
Posts: 6Questions: 1Answers: 0
I'd like to default sort a column (know how to do this) AND hide the sorting option on my other columns. Is this possible with DataTables? I can't find the option.
Thanks!
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Use columns.orderable.
https://datatables.net/reference/option/columns.orderable
Thanks tangerine, but I'm using columns orderable for my last column (date). What I want is to NOT have the rest of my columns orderable (while having my date column orderable).
As Tangerine mentioned you would use
columns.orderable
and set all but the last tofalse
. Something like this example:http://live.datatables.net/muqogixo/1/edit
Kevin
Thank you for clarifying kthorngren, much appreciated. And to tangerine: Please accept my apology as it seems you answered it already. Thank you too.
No problem. You're welcome.
Hi tangerine (or someone else?), I really didn't want to bug anyone (again), but I have tried so many different combinations to get this to work in the table tag and none do.
Could some please spell it out for me before I go bald?
I use wet4, using a cms with no option to add custom javascript. This is what I have so far:
<table class="wb-tables table table-bordered table-hover mrgn-tp-lg" data-wb-tables="{"order": [1, "asc"]}" data-page-length="50">
Now, how do I add this to it?:
columnDefs: [
{
targets: [0, 1, 2, 3, 4],
orderable: false
Thanks so much if someone can help.
That's a good question. You would do this:
data-column-defs='[{"targets": [0,1,2], "orderable": false}]'
For example:
http://live.datatables.net/nozifibi/1/edit
It also sets the initial table order to one of the other columns.
Kevin
Thank you very much Kevin. I'll give that a try tomorrow morning. I'll have to exchange the " with
"
and other stuff (due to my cms), but it should be fine.Much appreciated!
Worked great! Thanks Kevin