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:
In this article, we see how to integrate razorpay payment gateway in laravel 9. As you all know if you are developi...
Apr-11-2022
In this article, we will see localization - laravel localization example. Laravel's localization features provide a...
Nov-06-2020
Many times we need requirements to check the occupied disk space of the server on the admin side and we are checking man...
Jul-29-2020
In this article, we will see the laravel 9 livewire datatable example. Here, we will learn how to use livewire data...
Nov-30-2022