Sorting enabled when it should not

Sorting enabled when it should not

mathiemathie Posts: 36Questions: 0Answers: 0
edited October 2009 in Bug reports
Summary: The table is automatically sorted when it should display in original order. The test is a simple table with only one column (name).

Version: 1.5.4d
Header: Name
Data: row1=Betty, row2=Albert, row3=Alfred
Options: {"bSortable":false}

[code]

Name
BettyAlbertAlfred

$(document).ready(function() { $("#myTable").dataTable({
"bJQueryUI":true,"bAutoWidth":false,"bStateSave":false,
"bPaginate":false,"bFilter":false,"aoColumns":[{"bSortable":false}]}
);});

[/code]

The table is displayed with Betty at the bottom.

Thanks,
Son

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    edited October 2009
    Hi Son,

    I don't believe that this is actually a bug in DataTables - but rather more of a grey area :-). You haven't disabled sorting (bSort), and as such DataTables will attempt to sort on the first column by default. If you had more that one column, and you wanted others to be sortable, you would use aaSorting: [[1, 'asc']] (for example) to make the sorting occur on the second column by default.

    One could say that this is wrong and DataTables shouldn't attempt to sort the first column if it is initially non-sortable. However, I wanted to leave it flexible such that you have the sorting occur initially, and then not in future (a bit of a back-handed trick really, but it could be useful :-) ).

    So in the case of your one column table above, I'd suggest bSort:false. In a multiple column table, aaSorting with your required default.

    Regards,
    Allan
  • mathiemathie Posts: 36Questions: 0Answers: 0
    edited October 2009
    Thanks for the clarification. I didn't notice that bSort is the global setting. If possible, please add this note into the documentation (http://datatables.net/usage/features) so someone else doesn't ask the same question :)

    Or a check could be made to see if any column is sortable, if not, turn off sorting. Right now I'm doing this logic in my generic PHP class that generates the HTML/JS code.

    Son
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Son,

    I think that the argument of not having sorting enabled on any column, but still doing an initial sort (perhaps the original table data is unsorted, and you want to have it sorted, but not allow the user to define the sorting for whatever reason...) is equally part of the 'grey' area of this particular subject in DataTables. As this could actually be useful, and increases the flexibility of DataTables, I will be leaving sorting turned on, even if all columns are marked as unsortable for the moment.

    Having said that, yes I agree that the documentation could do with a bit of clarification on this topic and I'll look at this shortly.

    Regards,
    Allan
  • mathiemathie Posts: 36Questions: 0Answers: 0
    When I set bSort:false, all col headers don't get jQueryUI theme applied. It should instead apply the default state without sorting icons/events.

    Thanks,
    Son
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Son,

    Yes they probably should! I'll have a look at this and get back to you on a fix.

    Regards,
    Allan
  • borisavborisav Posts: 5Questions: 0Answers: 0
    does this mean there is no way to disable auto sorting of the first column or any other column?
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi borisav,

    No, that's not the case. You can disable the auto sort that DataTables performs on initialisation by setting the aaSorting parameter to being an empty array, eg:

    [code]
    $(document).ready( function() {
    $('#example').dataTable( {
    "aaSorting": []
    } );
    } );
    [/code]
    Regards,
    Allan
  • borisavborisav Posts: 5Questions: 0Answers: 0
    great thank you!
  • mathiemathie Posts: 36Questions: 0Answers: 0
    Hi Allan,

    Any update on "bSort:false" and no jQueryUI theme on headers?

    Thanks
    Son
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Son,

    Not yet I'm afraid - all the time I've had for DataTables this week has been support stuff rather than development really :-(. I'll try to look at it soon though. It's no. 1 on my do to list.

    Regards,
    Allan
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Son,

    Quick update on this - the issue is now addressed by v1.5.5. This should work nicely for you now :-)

    Regards,
    Allan
This discussion has been closed.