Datatable disable sorting on particular column example
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
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Create Dynamic Treeview Example using JQuery Ajax in PHP MySQL
- PHP - Dynamic Drag and Drop table rows using JQuery Ajax
- PHP Codeigniter 3 - Jquery Ajax Autocomplete Search using Typeahead
- Codeigniter 3 Datatables Ajax Example From Scratch
- PHP - jquery datatables with mysql database example from scratch
- jQuery Ajax X-editable bootstrap plugin to update records in PHP Example
- Laravel 5 - Implementing datatables tutorial using yajra package
- How to Allow Only One Checkbox Checked at a Time in JQuery?
- How to Check Object is Empty or Not in JQuery?