I understand this is a well-known topic, but I’m still searching for a solution to my issue.
I am trying to sort a table by a numeric field, however, Make’s ‘sort()’ function sorts alphanumerically rather than numerically. This means that if I input 10, 1, 14, and 4, I get an output of 1, 10, 14, 4.
The field I am sorting by is definitely a numeric field. Is there a solution to this problem?
In this article (Sort array by a number), someone suggested a custom module, but it is outdated and no longer works.
This is not completely true (from what I know), but it fully depends on your data type. If you have a variable which is an integer, it would sort if numerically. You can see it here:
So make sure the numbers you have, are actually integers (by hovering over the output, it shows the data type). In the case these are strings you can use the parseNumber() function
Thank you very much for your suggestion to convert the array to JSON and use the “Custom JS” module for numerical sorting. This method indeed seems very effective for sorting arrays of collections by numbers.
However, it’s important to note that this solution involves using a paid tool. In our case, we are looking for a free solution to meet our needs. Do you have any ideas or alternatives that could be used without incurring additional costs?
We greatly appreciate your help and advice, and remain open to other suggestions or ideas.
Thank you for pointing out the importance of data types in sorting operations. In my case, I’m confident that the field I’m working with is indeed an integer, as its value is derived from a ParseNumber() function.
Despite this, I’m still encountering the issue where the ‘sort()’ function seems to sort the numbers alphanumerically rather than numerically.
Any further insights or suggestions would be greatly appreciated.