Number sorting

Number sorting

ZeynalZeynal Posts: 11Questions: 4Answers: 0

Hi! How can I sort numbers correctly?

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    0,0,0,0,1,13,126,133? That's my best guess ;)

    If they're sorting like that, it's because DataTables is treating them as a string rather than a number. It would do this most likely is there are cells with non-numeric data.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • ZeynalZeynal Posts: 11Questions: 4Answers: 0

    But there is no non-numeric data

  • ZeynalZeynal Posts: 11Questions: 4Answers: 0

    Thas is how <td> looks like! Maybe nesting confuses DT?

  • ZeynalZeynal Posts: 11Questions: 4Answers: 0

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    There is lots of non-numeric data there. Specifically whatever is in the nested table tag is going to cause the issue. DataTables will strip out HTML by default, but whatever text is in the nested table will be included in the sort data.

    Given that this looks like generated HTML, I think your best option here would be to add the data-order attribute to your td - e.g.:

    <td data-order="26">
     ...
    </td>
    

    That way DataTables can then sort on that.

    Allan

  • ZeynalZeynal Posts: 11Questions: 4Answers: 0

    Do you know how to add data-order to td here?

  • ZeynalZeynal Posts: 11Questions: 4Answers: 0

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited January 2023

    Can you not modify the HTML being returned by the matching_assets controller at the server-side? Do you not control that code?

    If not, then you'll need to create an ordering plug-in that will work for the type of data structure you can in that column.

    Allan

Sign In or Register to comment.