Disable Sorting On Specific Columns In Datatable

WebSolutionStuff | Aug-24-2020 | Categories : jQuery

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 if you want to disable ordering, search or visibility for specific column then you can use columnDefs.

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

$(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 */
     }]
   });
});

 

Featured Post



Follow us
facebooklogo github instagram twitter