jQuery DataTables: Turn off sorting of a particular Column

You can also disable sorting feature of any column of the table you want in different ways. There are simple and easy to use options to disable sorting of columns in jQuery DataTables..

One is passing index and the other is passing class name of the column.

Passing Index of Column

You can also pass an array of indices of columns.

Note: the first index starts with zero ‘0’

$targetTable.dataTable(
  "aoColumnDefs" : [
 {
   'bSortable' : false,
   'aTargets' : [ 2, 5 ]
 }]
});

Its also possible to pass the class name of the table header you dont not want to have sorting feature.

<!-- The example contains embedded ruby code ->
<tr>
   <th><%= t(:name) %></th>
   <th class="text-holder"><%= t(:description) %></th>
   <th><%= t(:created_on) %></th>
   <th><%= t(:type) %></th>
   <th class='action'><%= t(:action) %></th>
 </tr>
$targetTable.dataTable(
  "aoColumnDefs" : [
 {
   'bSortable' : false,
   'aTargets' : [ 'action', 'text-holder' ]
 }]
});

you can also use negative index like this:

$('.datatable').dataTable({
    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
    "sPaginationType": "bootstrap",
    "aoColumnDefs": [
        { 'bSortable': false, 'aTargets': [ -1 ] }
    ]
});

One thought on “jQuery DataTables: Turn off sorting of a particular Column

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s