Disable Sorting On Specific Columns In Datatable

Websolutionstuff | Aug-24-2020 | Categories : jQuery

In this article, we will see how to disable sorting on specific columns in datatable. If you want to remove the sorting arrow or disable sorting on the specific columns or all columns in datatable then you need to use columnDefs in jquery. you can remove sorting arrows for one column or more than one column in the datatable using jquery. Also, you can disable the sorting and ordering of all columns in datatable.

Datatable provides many features like sorting, pagination, search, and ordering for the specific column but many times some features are not useful as per the client's project requirements if you want to disable ordering, search or visibility for the specific columns then you can use columnDefs.

ColumnDefs provide to set a parameter that 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 */
     }]
   });
});

 


You might also like:

Recommended Post
Featured Post
How To Integrate Razorpay Payment Gateway In Laravel 9
How To Integrate Razorpay Paym...

In this article, we see how to integrate razorpay payment gateway in laravel 9. As you all know if you are developi...

Read More

Apr-11-2022

Localization - Laravel Localization Example
Localization - Laravel Localiz...

In this article, we will see localization - laravel localization example. Laravel's localization features provide a...

Read More

Nov-06-2020

How To Check Occupied Disk Space In Laravel
How To Check Occupied Disk Spa...

Many times we need requirements to check the occupied disk space of the server on the admin side and we are checking man...

Read More

Jul-29-2020

Laravel 9 Livewire Datatable Example
Laravel 9 Livewire Datatable E...

In this article, we will see the laravel 9 livewire datatable example. Here, we will learn how to use livewire data...

Read More

Nov-30-2022