How to disable sorting with jquery datatable

By FoxLearn 3/5/2025 6:32:55 AM   925
To disable sorting in a jQuery DataTable, you can use the ordering option in the DataTable initialization.

Setting ordering to false will prevent sorting functionality on the table.

$('#table').dataTable( {
  "ordering": false // Disable sorting
} );

This will disable the sorting functionality for all columns in the table. If you want to disable sorting only on specific columns, you can use the columnDefs option.

For example, disable sorting on specific columns (e.g., columns 0 and 1):

$(document).ready(function() {
    $('#example').DataTable({
        "columnDefs": [
            { "orderable": false, "targets": [0, 1] }  // Disable sorting on column 0 and 1
        ]
    });
});

This way, sorting will be disabled for the specified columns, but the rest of the table will still be sortable.