How to Disable Sorting on a Column in jQuery Datatables Plugin CodeUnit 19 APR 2010

I’ve mentioned the wonderful jQuery plugin Datatables a number of times before, the awesome little trick that instantly transforms any HTML table fed to it into a fully sortable, paginated, searchable and zebra-striped table, requiring the most minimum of coding to implement.

Today’s quick tip is on how to disable sorting on specific columns, in the event when it simply doesn’t make sense for a user to be able to sort by that particular column in your table.

As per usual, the trick lies in setting this up at table initialization, making use of the handy bSortable property that can be applied to a column. The default value for this property is true, meaning you can specifiy it as null and it will remain sortable, but if you wish to remove the ability to sort then you need to explicity set it to false for that column. Seeing this in action, let’s have a look at the example below. If you can imagine that we have a four column table, I’m now going to turn off sorting for column three: 

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

And that’s really it. Pretty simple, after all!

To protect this man's sanity, turn off sorting now!

Related Link:

Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.

  • Andy Rose

    Thanks Craig, just what I was looking for.
    jQuery datatable really is very good although it is a shame the api documentation isn’t a little more intuitive with a few more code samples.

  • Asifsomy

    Nice tutorial, But i m looking for something else. May be you can help. I have column in my table that shows record number. for example | Record # | Name |. When user sorts Name column values of record number are also sorted accordingly. I want that Record # column should not sort accordingly. It should stay as it was at the time of loading.

    Record # should always be like 1,2,3 and so on, not 2,1,3

  • Whitakersp

    what about if you have a dynamic table and don’t know the full structure?

  • Matthew Buck

    Exactly what I needed. Thanks!

  • Rhiane Caña

    Great!.. Thanks for the helpful post… :)

  • Anders Malmgren

    A better way todo this is

    .dataTable({ aoColumnDefs: [{ bSortable: false, aTargets: [0]}] });

    This way you do not need need to know the number of columns, if you add a column you wont break anything aTargets: [0] means that it will target the first column.

    • Nice tip!

    • 176157898

      thanks very much!

    • Chuch Den

       I got this error
      XML descendants internal method called on incompatible Object
      …’.datatable1′)..dataTable({ aoColumnDefs: [{ bSortable: false, aTargets: [0]}] }…

  • Ankur Verma


    Tutorial Nice Exaplanation

  • J Hopley

    Legend, worked like a charm, kiss mother fucking kiss!

  • Chuch Den

    I got this error
    a.aoColumns is undefined
    help me please

    My code here :
    $(document).ready(function() {
    $(‘.datatable1’).dataTable( {
    “aoColumns”: [
    { “bSortable”: false },
    } );

    my table 6 columns

  • Jeremy

    If you have dynamic tables and more than one table on your site, this is what I made and it works for me. All you have to do is add a no-sort class to the th.

        var dontSort = [];
        $(‘.dataTable .table’).each(function () {
            var tmpID =;
            if (dontSort[tmpID] === undefined) {
                dontSort[tmpID] = [];
            $(‘#’+tmpID+’ th’).each(function () {
                if ( $(this).hasClass( ‘no-sort’ )) {
                    dontSort[tmpID].push( {
                        “bSortable”: false
                    } );
                } else {
                    dontSort[tmpID].push( null );
            } );
        } );
        for (var tmpID in dontSort) {
            $(‘.dataTable #’+tmpID).dataTable({
                “aoColumns”: dontSort[tmpID]

  • is there anyway we can disable the sort on certain column.

    • romualdo


      “aoColumnDefs”: [


      “bSortable”: false,

      “aTargets”: [ 0 ]




  • Arun

    Check this site for the answer…its working correctly..

  • Fernando Ingunza

    Craig Lotter