I am using the jQuery datatables plugin to sort the table fields. My question is how do I disable sorting for a particular column? I have tried with the following code, but it did not work:
"aoColumns": [
{ "bSearchable": false },
null
]
I have also tried the following code:
"aoColumnDefs": [
{ "bSearchable": false, "aTargets": [ 1 ] }
]
but this still did not produce the desired results.
To make a first column sorting disable, try with the below code in datatables jquery. The null represents the sorting enable here.
Disable Sorting on a Column in jQuery Datatables
The code will look like this:
To update Bhavish's answer (which I think is for an older version of DataTables and didn't work for me). I think they changed the attribute name. Try this:
Using Datatables 1.9.4 I've disabled the sorting for the first column with this code:
EDIT:
You can disable even by using the
no-sort
class on your<th>
,and use this initialization code:
EDIT 2
In this example I'm using Datables with Bootstrap, following an old blog post. Now there is one link with updated material about styling Datatables with bootstrap.
What I use is just add a custom attribute in thead td and control sorting by checking that attr value automatically.
So the HTML code will be
And JavaScript for initializing datatables will be (it will dynamically get the sorting information from table iteself ;)
If you set the FIRST column
orderable
property to false, you must also set the defaultorder
column otherwise it won't work since first column is the default ordering column. Example below disables sorting on first column but sets second column as default order column (remember dataTables' indexes are zero based).