'Alphanumeric sorting in Ag grid - Angular

I'm using the Ag grid framework to display data in my Angular project. I'm using Ag grid's default sorting feature for one of the columns that accepts string values and even includes alphanumerics. While sorting that column in ascending order, the values were arranged in the following manner, I'm not sure what logic was used to sort it out. I'd appreciate it if someone could explain things to me.




Ascending order:

{'10','110','120','170','20','30','31','80','A','BPS1'}


Solution 1:[1]

This is not really related specifically to AG Grid, but how strings with numbers are sorted.

You can verify this with the following:

var myNums = ['170','20','30','10','110','120','31','80','A','BPS1'];
myNums.sort();
console.log(myNums)

As you can see, that's the same result as if you sorted these values in the grid.

Now we have that out of the way, back to AG Grid, if you want to sort these values in a different way, you'll have implement a comparator which allows you to have Custom Sorting

There's an example showing how to do this in the documentation here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shuheb