Disable automatic sorting on the first column when using jQuery DataTables
Set the aaSorting
option to an empty array. It will disable initial sorting, whilst still allowing manual sorting when you click on a column.
"aaSorting": []
The aaSorting array should contain an array for each column to be sorted initially containing the column's index and a direction string ('asc' or 'desc').
In the newer version of datatables (version 1.10.7) it seems things have changed. The way to prevent DataTables from automatically sorting by the first column is to set the order
option to an empty array.
You just need to add the following parameter to the DataTables options:
"order": []
Set up your DataTable as follows in order to override the default setting:
$('#example').dataTable( { "order": [], // Your other options here...} );
That will override the default setting of "order": [[ 0, 'asc' ]]
.
You can find more details regarding the order
option here:https://datatables.net/reference/option/order
var table;$(document).ready(function() { //datatables table = $('#userTable').DataTable({ "processing": true, //Feature control the processing indicator. "serverSide": true, //Feature control DataTables' server-side processing mode. "order": [], //Initial no order. "aaSorting": [], // Load data for the table's content from an Ajax source "ajax": { "url": "<?php echo base_url().'admin/ajax_list';?>", "type": "POST" }, //Set column definition initialisation properties. "columnDefs": [ { "targets": [ ], //first column / numbering column "orderable": false, //set not orderable }, ], });});
set
"targets": [0]
to
"targets": [ ]