I am using the dataTables.js jQuery plugin.
The first column of my table is a row counter, so I don't want it be sortable by the user. The last column contains some action link that the user can perform on a row. How can I make these two columns unsortable?
Note: I am using pipeline (server-side process) mode of datatables.
This is done by setting bSortable to false:
/* Using aoColumnDefs */
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] }
] } );
} );
/* Using aoColumns */
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
{ "bSortable": false },
null,
null,
null,
null
] } );
} );
DataTables 1.10+ also supports HTML5 data-
style attributes, including data-sortable="false"
, which makes the column ineligible for sorting:
<table>
<thead>
<tr>
<th data-sortable="false">Row</th>
<th>Name</th>
<th>Join Date</th>
<th>Organization</th>
<th data-sortable="false">Options</th>
</tr>
</thead>
<tbody>
<tr>
[etc]
</tr>
</tbody>
</table>
See this demo in jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With