Reputation: 1093
Suppose i have the table like below :
And I want to disable sorting of Action Column
<!--index.html-->
<table class="table table-striped table-bordered post-list-table" id="table" >
<thead>
<tr>
<th>Title</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
</table>
<!--Script.js-->
$('#table').DataTable();
Upvotes: 16
Views: 39768
Reputation: 101
If u want to disable sorting for all columns then u can do $(th).unbind();
in footable
Upvotes: 0
Reputation: 121
Do this in jQuery
var table = $('#tbl').DataTable({
"columnDefs": [{ targets: 'no-sort', orderable: false }]});
and add a class 'no-sort' to whatever headers you want to disable sort like this..
<th class="no-sort">Header n</th>
Upvotes: 7
Reputation: 333
Add a class to columns which you want to disable sort
<th class="no-sort">Operations</th>
then add the following style to your css
table.datatable thead th.no-sort {
background: none;
pointer-events: none;
}
Upvotes: 4
Reputation: 1530
Try adding : columns.orderable
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
<!--Script.js-->
$('#table').DataTable( {
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table class="table table-striped table-bordered post-list-table" id="table" >
<thead>
<tr>
<th>Title</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
</table>
Upvotes: 33
Reputation: 6587
Try this
$('#table').dataTable({
// display everything
"iDisplayLength": -1,
"aoColumns":[
{"bSortable": true},
{"bSortable": true},
{"bSortable": false}
]
});
for reference - https://stackoverflow.com/a/7878609/1982631
Upvotes: 2