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
How To Validate Phone Number Using jQuery
How To Validate Phone Number U...

In this article, we will see how to validate phone numbers using jquery. We will learn different methods of validat...

Read More

Oct-24-2022

How to Create Form Request Validation in Laravel 10
How to Create Form Request Val...

Hey there! Today, I want to talk to you about a super useful feature in Laravel 10 called form request validation. If yo...

Read More

Feb-23-2024

How To Send Email In Laravel 9 Using Mailtrap
How To Send Email In Laravel 9...

In this article, we will explore the process of sending emails in Laravel 9 using Mailtrap. We will delve into how Larav...

Read More

Jul-27-2022

How To Get Hourly Data In MySQL
How To Get Hourly Data In MySQ...

In this tutorial, we will see how to get hourly data in mysql. Many times we need to get hourly data or we are required...

Read More

Feb-04-2022