Sorting issues (1-10-12-2-20 etc)
Sorting issues (1-10-12-2-20 etc)
EmilBr78
Posts: 6Questions: 2Answers: 0
Heya!
I use the most basic table setup:
$(document).ready(function(){
$('#datatable').DataTable()
} );
...and I'm having issues with it not sorting properly. The numerical fields are lexicographically sorted, probably due to whitespace (if I've googled correctly). How do I fix it?
Here's the table in action:
https://www.cyberzoo.se/ciklider-artregister-lista.html
Best regards
Emil
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
FWIW, adding the examples found here:
https://datatables.net/reference/option/columns.type
...breaks the script.
I'm currently getting an error:
when loading the page.
However, I can see the plain unformatted table. If we take the Storlek (cm) column as an example, it contains numbers such as:
The first one obviously is fine. The second, you would need a custom plug-in to sort. The third and fourth, I'm not sure if they are both meant to be decimal characters? If so, you need to pick one and be consistent with it.
Allan
Hi Allan! Sorry for the late reply! The issues you pointed out have been corrected, the table is essentially the way we want it now, we've added a min/max search that works like a charm. But it still doesn't sort the columns the way we want and I can't see what's wrong.
If you add "30" to the min search box and "120" to the max box, and then sort the "Volym"-column you'll see what's wrong.
A number of the cells in that column have
which is non-numeric, hence the issue. If you put-
or an empty string in, it will work okay.Allan
Best regards
Emil