order() method

order() method

nefiganefiga Posts: 8Questions: 4Answers: 0
edited May 2016 in Free community support

It seems that the indexes passed to the DataTable().order() method are for visible indexes. Is there a way to have this sort by the original column index? (similar to how the column selector works for original order, e.g. it is possible to do

DataTable().colums([0,1,2], {'order': 'original'})

selector to get the 0, 1, and 2 columns as originally specified).

I am looking for this as I have stored a table state which includes ordering. The table state save method saves the original column index, so when retrieving it, I'm stuck as the method to initialize a new order takes the visible index, and I'd rather not have to parse through columns and ColReorder variables to find this out (not to mention any other operations which may change the column order).

The column().order() method almost works, but it breaks down when you have a 2+ column sort with different sorting directions.
e.g.

DataTable().column(0, {'order' : 'original'}).order('asc').column(1, {'order' : 'original'}).order('desc').draw();

only sorts the last entry, and using

columns([0,1]).order('asc')

forces both to be "asc".

Thank you for any help

This question has an accepted answers - jump to answer

Answers

  • nefiganefiga Posts: 8Questions: 4Answers: 0

    It's almost like there should be a column selector type to the order() method, like

    DataTable.order([ [1, 'desc'], [2, 'asc'] ], {'order' : 'original'});
    

    but it does not appear that such a thing exists.

  • nefiganefiga Posts: 8Questions: 4Answers: 0
    edited May 2016

    In regards to using {'order' : 'original'}, it seems that it does not really work with ColReorder. See jsfiddle:

    https://jsfiddle.net/719media/nwm96nv6/

    Issue created on github:

    https://github.com/DataTables/DataTables/issues/816

  • allanallan Posts: 64,090Questions: 1Answers: 10,569 Site admin
    Answer ✓

    Replying with my comment from the github issue that was opened on this topic:

    {'order': 'index'}

    This applies to the row ordering, not the columns. See the selector-modifier documentation:

    The order modifier provides the ability to control which order the rows are processed in.

    There is no option to get the columns in original index order using the selectors once a ColReorder has been performed. Having said that you can use the colReorder.transpose() method to convert from a current column index to the original if you require.

    Allan

This discussion has been closed.