aaSorting returning extra element?

aaSorting returning extra element?

bill.martinobill.martino Posts: 38Questions: 0Answers: 0
edited January 2011 in Bug reports
I am trying to refer to the aaSorting array as such:

// get current sorting
var currentSort = oTable.fnSettings().aaSorting;

as i loop through the array, which at first contains only one element, I would expect to get back

3,desc

however, I am receiving

3,desc,1

any ideas?

Replies

  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin
    This is intentional. The 1 indicates to DataTables where in the array of sorting options (asSorting) the current sort is. For example you could specify [ 'asc', 'desc', 'asc' ] for asSorting - that would mean the order would be:

    click 1: asc
    click 2: desc
    click 3: asc
    click 4: asc
    click 5: desc
    ...

    Obviously you typically wouldn't want to do that - but it's an option in DataTables :-)

    Another example where it is useful is if you have asSorting [ 'asc', 'desc' ] on the first column, but specify the default sorting as 'desc'.

    So something that is required internally - if you have a look at the initialisation code, you can see where DataTables will add this to the array.

    Allan
This discussion has been closed.