I am using jQuery DataTables plugin to sort table data. I have four columns: Name, Position, Office and Age. What I want is user to be able to sort only Name and Age columns, not all the columns. But I am not able to stop sorting on OTHER columns. Can you please suggest something?
I am using jQuery DataTables plugin to sort table data. I have four columns: Name, Position, Office and Age. What I want is user to be able to sort only Name and Age columns, not all the columns. But I am not able to stop sorting on OTHER columns. Can you please suggest something?
Share Improve this question edited Jul 20, 2015 at 4:54 Gyrocode. 58.9k16 gold badges156 silver badges191 bronze badges asked Jul 17, 2015 at 6:50 love thakkerlove thakker 4702 gold badges13 silver badges29 bronze badges 1- Here is my fiddle. – love thakker Commented Jul 17, 2015 at 6:51
1 Answer
Reset to default 9This code disable sorting, 0 - index of column. For old version
aoColumnDefs: [
{
bSortable: false,
aTargets: [ 0 ]
}
]
for DataTables 1.10+
columnDefs: [
{ orderable: false, targets: 0 }
]
Especially for example, you need this
$(document).ready(function() {
$('#example').dataTable( {
"order": [[ 0, "desc" ]],
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
null
]
} );
} );
fiddle