Sorting select filter numbers as numbers not strings
Sorting select filter numbers as numbers not strings
silkspin
Posts: 152Questions: 34Answers: 5
I'm guessing there must be an example of this somewhere but I can't find one. I want to sort numbers in a select input filter by either ascending or descending. In this example the salary sorts as a string and not numerically by value.
https://datatables.net/examples/api/multi_filter_select.html
Is this possible?
This question has an accepted answers - jump to answer
Answers
You can perform your own custom sorting. You can use a function with the
sort()
API to customize the sort. Here is an example:http://live.datatables.net/fapavaho/1/edit
It calls the custom function if processing the Salary column.
Kevin
Thanks very much @kthorngren, that is fantastic! It was a bit more complicated than I had expected. I thought something might've already been built in to handle it, but your test works great.