Disable Sorting On Specific Columns In Datatable

Websolutionstuff | Aug-24-2020 | Categories : jQuery

In this article, we will delve into the process of disabling sorting for specific columns in Datatables. If you find the need to eliminate sorting arrows or prevent sorting on particular columns, or even across all columns in Datatables, you can achieve this through the use of the columnDefs feature in jQuery.

With columnDefs, you can remove sorting arrows for one or more columns in your Datatable using jQuery. This gives you the flexibility to disable sorting and ordering for columns as per your project's specific requirements.

While Datatables offers a rich set of features, including sorting, pagination, search, and column ordering, there are instances where certain features may not align with the client's project needs. If you need to disable ordering, search, or visibility for specific columns, columnDefs provides the means to configure these options tailored to individual columns in your Datatable.

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


 

Conclusion:

In conclusion, we have explored the effective method of disabling sorting for specific columns in Datatables. By leveraging the columnDefs feature in jQuery, we can easily remove sorting arrows, prevent sorting on particular columns, or even disable sorting across all columns within our Datatables.

 


You might also like:

Recommended Post
Featured Post
Laravel 9 Form Collective Example
Laravel 9 Form Collective Exam...

In this article, we will see laravel 9 form collective example. Here, we will learn how to use collective form and...

Read More

Jan-20-2023

How To Solve The Page Expired 419 Error In Laravel
How To Solve The Page Expired...

In this article, we'll learn how to resolve the "419 page expired" error in Laravel. You might have encoun...

Read More

Jun-28-2020

How To Add Datepicker In Angular 15 Material
How To Add Datepicker In Angul...

In this tutorial, I will guide you through the process of adding a datepicker component to your Angular 15 application u...

Read More

Jun-28-2023

Laravel 9 Paypal Payment Gateway Integration
Laravel 9 Paypal Payment Gatew...

In this article, we will see laravel 9 paypal payment gateway integration. Here, we will learn how to integrate the...

Read More

Jan-17-2023