Reputation: 609
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?
Upvotes: 0
Views: 4788
Reputation: 1422
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.
Upvotes: 0
Reputation: 4182
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:
$('#example').dataTable( {
"columnDefs": [
{ "orderable": false, "targets": 0 }
]
} );
"columns": [
{ "orderable": false },
null,
null,
null,
null
]
Upvotes: 2