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:
- Read Also: Datatables Show And Hide Columns Dynamically In jQuery
- Read Also: Laravel 9 Refresh DataTable Without Reloading Page
- Read Also: Datatables Expand/Collapse Columns
- Read Also: Autotab To Next Input Field JQuery