Disable Sorting On Specific Columns In Datatable

Websolutionstuff
1 min readJan 9, 2021

--

  • In this example I will show you how to disable sorting on specific columns in yajra datatable. If you want to remove sorting arrow or disabled sorting on specific column or all column in yajra datatable then you need to use columnDefs in jquery.
  • Yajra datatable provide many features like sorting, pagination, search, and ordering for specific column but many time some feature are not useful as per client’s project requirements 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.
$(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 */
}]
});
});

Thanks For Reading !! 😃

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet