Disable sorting

Disable sorting

enne87enne87 Posts: 5Questions: 0Answers: 0
edited August 2011 in Plug-ins
HI guys!
I have my datatable with two colums. In the first column I store some names. Now, I don't want the names to be automatically sorted alphabetically. I tried to disable sorting with the following code:
[code]
$('#jTable').dataTable(
{
"aoColumns": [{ "bSortable": false },{ "bSortable": false }]
} );
[/code]

But this also doesn't work. As soon as a new entry is inserted, it is positioned in alphabetic order.
Can anyone give me a hint please?

Thanks in advance.

Replies

  • cdaiglecdaigle Posts: 57Questions: 0Answers: 0
    There are 2 things I can think of that you can try.

    First, try setting "bSort" to false. (http://datatables.net/usage/features#bSort )
    Note that this will disable sorting all around, so there is no need to disable it on individual columns.
    [code]
    $('#jTable').dataTable(
    {
    "bSort" : false
    } );
    [/code]

    Second, try setting aaSorting to empty. (http://datatables.net/usage/options#aaSorting )
    Note that this would be good to try if you still want to allow some other column(s) to be sortable.
    [code]
    $('#jTable').dataTable(
    {
    "aaSorting" : [[]]
    } );
    [/code]

    Let us know if either works for you.

    Hope it helps,
    Chris.
  • vbullingervbullinger Posts: 2Questions: 0Answers: 0
    What if I have three columns and want the first two to sort, but not the last one?
  • dmsdevdmsdev Posts: 2Questions: 0Answers: 0
    @vbullinger You would do the following, assuming your table id is 'example'

    [code]
    // Using aoColumns
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumns": [
    null,
    null,
    { "bSortable": false }
    ] } );
    } );
    [/code]

    Which will disable the sorting on the last column but not the first two.
  • vbullingervbullinger Posts: 2Questions: 0Answers: 0
    Thanks, @dmsdev. By the way, why did they choose to use hungarian notation? Makes me cringe every time I see it.
  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    See: http://datatables.net/faqs#hugarian . Yes it was undoubtably a mistake, but can't it be changed now? Yes it could, but it would break _everything_, so for the sake of a few characters, I'm not yet willing to change it...

    Allan
  • larrydlefeverlarrydlefever Posts: 1Questions: 0Answers: 0
    at first, I thought my problem was with sorting, but now I'm not sure. what happens is that the user edits a cell inline, and, upon hitting enter, the rows get re-ordered; meanwhile, my fnOnEdited gets called with seemingly inaccurate rowId values, which screws up how I accumulate an array of "dirties" that I send to the server in one batch upon click on a special other button I created for that purpose. I've tried to disable sorting, but with no success. generally, I don't want rows to get re-ordered ever. how do I ensure that?
This discussion has been closed.