If you do not pass the user search function, the sort function sorts lexically, the numbers are transferred to strings and, therefore, happens, for example, β10β - to β3β. Therefore, the rows are sorted.
You can pass a custom function to the sort function, which determines the order of elements, in the case of numbers it will be an example (be careful, since the numbers in your example will be strings if you do not display / parse them by numbers):
var numsort = function (a, b) { return a - b; } var numbers = new Array(20, 2, 11, 4, 1); var result = numbers.sort(numsort);
Another example for strings:
var sortstring = function (a, b) { a = a.toLowerCase(); b = b.toLowerCase(); if (a < b) return 1; if (a > b) return -1; return 0; }
source share