Number sorting
Number sorting
Zeynal
Posts: 11Questions: 4Answers: 0
Hi! How can I sort numbers correctly?
Hi! How can I sort numbers correctly?
Answers
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
But there is no non-numeric data
Thas is how <td> looks like! Maybe nesting confuses DT?
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 yourtd
- e.g.:That way DataTables can then sort on that.
Allan
Do you know how to add data-order to td here?
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