Sorting Programmatically

Sorting Programmatically

hoffhoff Posts: 4Questions: 1Answers: 0
edited September 2015 in Free community support

I have a table which only has all the data crammed into 1 column. But I want to provide the user the ability to sort it based upon multiple hidden columns/variables.

I have seen examples of using fnSort and aaSort (when declaring the table). When I try to do the following it does not work:

view.table = $('#table-simple-units').DataTable({
                    dom: App.getTableDom(),
                    .........
                    .........
});

view.table.fnSort( [ [0,'asc'], [1,'asc'] ] );

It says fnSort is not a function and it seems like it's deprecated? What is the updated equivalent function to fnSort if I want to call it on my table variable?

I tried the following as well:

  view.table.order( [ [1,'asc'] ] );

And I get no error, but it does not update the table either. What am I missing?

This question has accepted answers - jump to:

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    edited September 2015 Answer ✓

    Yup, that's the legacy syntax. Documentation is here for the current version.

    http://datatables.net/examples/index

    Some examples of sorting. If you use the search engine, search for "order", not "sort". That's the current term.

  • hoffhoff Posts: 4Questions: 1Answers: 0

    Thank you ThomD,

    I figured out how to use the .order syntax and then draw the table. It works now, thank you.

    However, can you also tell me how to access the current ordering of the table?
    So when I do an ordering programmatically I want to read the current setting of the table.

    Thanks in advance.

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    Details are in the documentatoin on order().

    http://datatables.net/reference/api/order()

  • hoffhoff Posts: 4Questions: 1Answers: 0

    Thanks a bunch, I was accessing the function and not the array, silly mistake. Now it works!

  • hoffhoff Posts: 4Questions: 1Answers: 0
    edited September 2015

    If i have two columns, one that declares an amount, and a second that declares the maximum. How do I order on a calculated value between those two? I.e. use those two values to calculate the percentage of stock and then order the rows based upon that?

    Can I still do this using the order function?

This discussion has been closed.