I want the default sort order to be None-Descending-Ascending for Numbers

I want the default sort order to be None-Descending-Ascending for Numbers

ignatzignatz Posts: 3Questions: 2Answers: 0

Out of the box the sort order is None-Ascending-Descending. That's exactly what I want for A-Z sorts. However, for numerical sorts I want the reverse. In my data sets there are so many zeros and ones. Larger numbers are the exception and they are the things that I'm interested in having displayed.

In this situation I have dozens of data sets being generated from a reasonably complex XML data source. I use XSL to generate the table. The number of columns and the type of data varies a great deal, depending on the XML node that is being investigated.

Can I make a single, high level setting that says, "if the column is full of numbers, do the initial sort in descending order"?

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @ignatz ,

    There are a couple of things you could do.

    If the data is in the DOM, you can just check a cell in that column before initialising the table, then set order appropriately.

    If the data is coming from Ajax, or even if it is in the DOM too, you could run a similar check in initComplete and then call order() to change the order.

    Cheers,

    Colin

  • ignatzignatz Posts: 3Questions: 2Answers: 0

    I'm using PHP and SimpleXML to read in the XML data source, so, not in the DOM and not coming via Ajax. I was hoping that I wouldn't have to code for every different node but it looks like that is going to be the best way to control this.

    After posting I realised that much of the numerical data isn't presented in the table as numbers. By that stage it is wrapped in html code and often has hyperlinks, so the fact that datatables sorts in correctly is pretty cool.

This discussion has been closed.