Mitali
Mitali

Reputation: 111

jQuery DataTable: Disabling sorting for specific columns

I have 6 columns in my jQuery Data table and want to disable sorting for the first and last column.

I have used the following code:

$('#UserDetails').dataTable({
    "aoColumns": [
          { "bSortable": false },
          null,
          null,
          null,
          null,
          { "bSortable": false }
      ]
});

This code disables sorting for the last column but not the first.

Can someone please help?

Upvotes: 0

Views: 2407

Answers (3)

IronAces
IronAces

Reputation: 1883

For 1.10.13, you can use the following

$('#UserDetails').dataTable({
    "columnDefs": [
        {
            orderable: false,
            targets: [0,5]
        }
    ]
);

Upvotes: 1

Sri Tirupathi Raju
Sri Tirupathi Raju

Reputation: 819

In Jquery datatable usually we use last column for sending extrdata/payload so if you have 6 visible columns actually they are 7 columns so:

$('#UserDetails').dataTable({
    "aoColumns": [
          { "bSortable": false },
          {"bSortable": true},
          {"bSortable": true},
          {"bSortable": true},  
          {"bSortable": true},
          {"bSortable": false}, 
          {"bSortable": false, "bVisible":false} //invisible column
      ]
});

Upvotes: 0

faby
faby

Reputation: 7558

try this

$('#UserDetails').dataTable( {
      "aoColumnDefs": [
          { 'bSortable': false, 'aTargets': [ 0,5 ] }
       ]
});

where 0,5 are the indexes of the columns that you want to exlude from the sort

Upvotes: 1

Related Questions