DataTables: Disable Sorting on a Column Tips, Tricks and Tutorials 31 JAN 2014

datatables plugin logoDataTables is a fantastic jQuery-powered plugin that supercharges your ordinary HTML tables and as such is pretty much my de facto method for presenting tabular data.

I often include special ‘action’ columns in my table where I lump in all my row data manipulating buttons and thus don’t particularly want to allow DataTable’s column sorting option added to those columns. Thankfully disabling the sorting option on specific columns has now become particularly easy, thanks to the aTargets configuration option.

To achieve the column sorting function we make use of the aoColumnDefs configuration option to turn off the bSortable flag, using the aTargets label to control which columns the specified property definition applies to.

In practice:

"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [ 0,7,9 ] }]

Assuming my table has ten columns, this essentially turns off sorting for the first column, last column and the eighth column (remember, the column array is zero-indexed).

Related Link:

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • Arup


  • How about just adding;

    “aoColumnDefs”: [{‘bSortable’:false,’aTargets’:[‘action’,’no-sort’]}]

    as a default, then you can just add a class of no-sort to any th you want