Disable Sorting On Specific Columns In Datatable

In this example I will show you how to disable sorting on specific columns in datatable. If you want to remove sorting arrow or disabled sorting on specific column or all column in datatable then you need to use columnDefs in jquery. Datatable provide many features like sorting, pagination, search, and ordering for specific column but many time some feature are not useful as per client's project requirments.

Using datatable columnDefs function you can disable sorting on all columns, datatable sorting on specific column, datatables disable sorting on multiple columns, datatables remove sorting arrows for one column.

lets's see datatable disable sorting on particular column example.

 

ColumnDefs provide to set parameter allows you to assign specific options to columns in data tables.

"columnDefs": [ {
      "targets": 0,
      "searchable": false
    } ]
$(document).ready(function()
{
   $('#details').DataTable({
     'processing': true,
     'serverSide': true,
     'serverMethod': 'POST',
     'ajax': {
       'url':'/demo/details.php'
     },
     'columns': [
        { data: 'id' }, /* index - 0 */
        { data: 'name' }, /* index - 1 */
        { data: 'email' }, /* index - 2 */
        { data: 'phone_no' }, /* index - 3 */
        { data: 'country' } /* index - 4 */
     ],
     'columnDefs': [ {
        'targets': [3,4], /* column index */
        'orderable': false, /* true or false */
     }]
   });
});

 


You might also like :

FEATURE POSTS