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?

1 Answers

1
Avanthika On

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
]