DEV Community

loading...

Disable Sorting On Specific Columns In Datatable

websolutionstuff profile image Websolutionstuff Originally published at websolutionstuff.com ・1 min read

In this example I will show you how to disable sorting on specific columns in yajra datatable. If you want to remove sorting arrow or disabled sorting on specific column or all column in yajra datatable then you need to use columnDefs in jquery.

Yajra 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 requirements 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 */
     }]
   });
});
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide