Sorting by Number of Different Lengths
Sorting by Number of Different Lengths
Parmee
Posts: 3Questions: 1Answers: 0
Hey,
I'm facing a bug when sorting by a number of varying lengths. For example:
1
22
333
1111
22222
333333
When sorting the above it produces results like this:
1
1111
22
22222
333
333333
Rather than how it should be above.
Thanks,
This discussion has been closed.
Answers
It seems to work fine when using a plugin and specifying the table to use that type: https://datatables.net/plug-ins/sorting/natural
Though, unsure why this requires a plugin and isn't automatically detected like a standard number.
Thanks,
I was just going to suggest that plugin. Does that column have something other than numbers in it? The column type will be set to string if there are non-numeric elements in the column. The natural sorting plugin will work regardless of column type (number or string).
Kevin
Yes, there must be some data in the column that is non-numeric, which is causing DataTables to sort it as a string rather than as numbers.
The natural sorting plug-in is a good option for mixed numeric and non-numeric content.
Allan
Hey,
It might be that I'm using a render to apply HTML, though I'd have assumed the data-order=" " would be used rather than the HTML field?
Debug can be found here: http://debug.datatables.net/omuziz
Live Test: http://live.datatables.net/pihoyugu/1/
Screenshot: https://www.screencast.com/t/pV67QIDj
Thanks,
Thank you for the test case. There you have:
But there is no sorting plug-in of that name defined. Removing that let's it work as expected.
My guess is that that plug-in is doing a string sort.
Allan