0

I have tried many ways of disabling sorting on the first column. I have not been able to achieve it.

I have been able to disable all columns beside the first column using:

'columnDefs': [ {
'targets': [],
'orderable': false, // set orderable false for selected columns
}]

Can anyone help me, please?

2 Answers 2

2

Your columnDefs.targets is empty. You have to pass the index of the column where you want to disable sorting. For first column, you need to pass the first column's index, 0.

As per datatables documentation, you can disable ordering of first column in two ways:

  1. With columnDefs:
$('#example').dataTable( {
  "columnDefs": [
    { "orderable": false, "targets": 0 }
  ]
} );
  1. With columns:
"columns": [
    { "orderable": false },
    null,
    null,
    null,
    null
]
Sign up to request clarification or add additional context in comments.

4 Comments

jsfiddle.net/d12a9gxn - Works for me, can you share a jsfiddle with your config?
Where does it work? The sorting icon is still active on the first tab. Did you see?
Oh, you want to remove the initial default sorting? aaSorting: [] - This should be passed as a config option. I have removed the initial sort here - jsfiddle.net/xom4qdeL
Or you will have to do order: []
0

order is used to apply initial order (sort) to the table.
It can be used to apply initial sorting on any other column.
By default, DataTables use first column even if you disable sorting for that column using targets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.