ItSolutionStuff.com

Datatable Remove Sorting from Specific Column Example

By Hardik Savani • November 5, 2023
jQuery

If you want to remove sorting arrows or disable sorting on specific columns in datatables library than you can do it using columnDefs. we can simple disable ordering arrows from table in data tables js. even you are using with php, laravel, codeigniter, vue js etc. we can disable particular column sorting like one column, first column, last column, specific index.

Datatable library makes very simple pagination, sorting and searching. Datatables by default provide all function by default like ordering, pagination, listing searching for all table column. But 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.

You can see sample code of columnDefs:

'columnDefs': [ {

'targets': [1,3], /* column index */

'orderable': false, /* true or false */

}]

Example:

$(document).ready(function(){

$('#empTable').DataTable({

'processing': true,

'serverSide': true,

'serverMethod': 'POST',

'ajax': {

'url':'/ajax/users.php'

},

'columns': [

{ data: 'id' }, /* index = 0 */

{ data: 'name' }, /* index = 1 */

{ data: 'email' }, /* index = 2 */

{ data: 'gender' }, /* index = 3 */

{ data: 'city' } /* index = 4 */

],

'columnDefs': [ {

'targets': [1,2], /* column index */

'orderable': false, /* true or false */

}]

});

});

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

PHP MySQL Create Dynamic Treeview Example

Read Now →

PHP JQuery Chosen Ajax Autocomplete Example

Read Now →

PHP Ajax Drag and Drop Sorting Table Rows Example

Read Now →

Codeigniter JQuery Ajax Autocomplete Search using Typeahead

Read Now →

How to implement and use DataTables in CodeIgniter?

Read Now →

PHP Ajax Multiple Image Upload with Preview Example

Read Now →

PHP MySQL DataTables Server-side Processing Example

Read Now →

PHP Ajax Inline Editing using X-editable Bootstrap JS Example

Read Now →

How to Get the Current URL using JQuery?

Read Now →

PHP Check Word Exist in String or Not Example

Read Now →

How to Check If Element is Exists or Not in jQuery?

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →

How to Check Object is Empty or Not in JQuery?

Read Now →