How to Disable(false) sorting of one column from DataTables?

If you want to remove or hide or deleting sorting ascending and descending order arrows or disable sorting ascending and descending order on particular columns in datatables library also set “ordering”: false than you can do it using columnDefs. i can simple disable(datatable sorting false) ordering arrows from table in data tables js. even you are using with server side php, laravel, codeigniter, Angularjs, vue js etc. i can datatable sorting false the default sorting column sorting ascending and descending order like single column, first column, middle, last column, specific each index.

Enable Disable settings jQuery DataTables

in jquery datatable disable sorting on specific columns Example, Datatable library creates very easy pagination, sorting ascending and descending order as well as searching. Datatables by default provide all the function by default such as a ordering, pagination, listing searching for all table column. But if you want to disable ordering, search or visibility for particular column then you can use columnDefs.

Read Also:  javascript read text file line by line

here columnDefs support to set parameter allows you to assign particular jquery table options to columns in data tables.

Datatable disable sorting on particular column example

You can see sample code of columnDefs:

DataTables.Settings

'columnDefs': [ {
    'targets': [1,3], /* table column index */
    'orderable': false, /* here set the true or false */

 }]

DataTable sorting Settings

$(document).ready(function(){
   $('#product_list').DataTable({
     'processing': true,
     'serverSide': true,
     'serverMethod': 'POST',
     'ajax': {
       'url':'/ajax/products.php'
     },
     'columns': [
        { data: 'id' }, /* table index = 0 */
        { data: 'pname' }, /* table index = 1 */
        { data: 'pcode' }, /* table index = 2 */
        { data: 'price' }, /* table index = 3 */
        { data: 'desc' } /* table index = 4 */
     ],
     'columnDefs': [ {
        'targets': [1,2], /* table column index */
        'orderable': false, /* true or false */
     }]
   });
});

Read Also:  How to Open URL in New Tab using JavaScript

DataTable responsive Settings

$(document).ready(function() {
    $('#product_list').DataTable( {
        responsive: true
    } );
} );

Also Read: Server-side Processing DataTables using PHP with MySQL

remove sorting option from DataTables

var oTable = $('#product_list').dataTable( {
    "aoColumnDefs": [
        { "bSortable": false, "aTargets": [ 0, 1, 2, 3 ] }, 
        { "bSearchable": false, "aTargets": [ 0, 1, 2, 3 ] }
    ]
}); 

other Way

$('#example').DataTable({
    "ordering": false
});