46

Here is the code i am using

oTable = $('#example').dataTable({
                "bSort": false,
                "bStateSave":true,
                "aoColumns": [ 
                   { "bSortable": false },
                   { "bSortable": false },
                   { "bSortable": false } ] 
            });

The problem i'm having is that the table starts off blank and its populated by user input. Once the user starts to input things into the table, it sorts them by product ID. I'm trying to remove this sorting so that it just lists them as they are input.

EDIT: I have come to the conclusion that NONE of my initialization settings are working. I believe it has to do with the fnAddRow when the table is empty except for headers.

EDIT2: I've isolated it down to the fnAddData. When I initialize the table with trash data everything is formatted as its supposed to be but then once i use the fnAddData, it removes all formating

1

7 Answers 7

103

Try this:

$(document).ready( function () {$('#example').dataTable( {
    "bSort": false
  } );
} 
Sign up to request clarification or add additional context in comments.

Comments

26

try this:

this is to disable initial sort

$(document).ready( function() {
  $('#example').dataTable({
    "aaSorting": []
});
})

2 Comments

This should be default setting on data tables. Thanks for this.
Thank you. Search brought me here and the answer disabled all sorting, the initial is what I was after. Saved me some time having this here.
8

Since version 1.10 of DataTables, you can use the following option to disable the ordering completely:

$('#dataTable').dataTable({
  ordering: false
});

Also see: https://datatables.net/reference/option/ordering

Comments

2

bSort ( http://datatables.net/ref#bSort ) is the correct way to disable sorting in DataTables. Perhaps you can link to your example which shows sorting still enabled with this parameter set please?

1 Comment

I can't actually link the page due to a login required to populate the drop down menu from a database. I suspect it has to do with having a blank table and then adding rows. I have tried every method i saw on the datatables.net site and nothing seems to be working. The sorting always appears
2

try this one,

set data-orderable ="false" in the table header tag

<table id="orders">
   <thead>
     <tr>
       <th data-orderable="false">ID</th>
       <th>Customer Name</th>
       <th data-orderable="false">Total</th>
       <th>Date</th>
       <th data-orderable="false">Action</th>
     </tr>
   </thead>
</table>

Comments

1

use the below code

"aoColumnDefs": [
  { "bSortable": false, "aTargets": [ 0 ] }
] } );

OR use the link http://datatables.net/ref#bSortable

Comments

0

Default sorting can be set by asSorting parameter. Please see:

http://datatables.net/usage/columns

3 Comments

i DONT want to have sorting though
add a hidden field with timestamp. Set default sorting by this time. Items will show up in the same order as they were added.
I did this except with index numbers. The problem is none of the initial parameters are being kept after fnAddData runs. I believe somewhere in the fnAddData code, the oSettings field is being cleared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.