I have a grouping grid that groups by a field, lets say the group is 'team'. Then all the players in that team have a number and other fields such as name, contract start and end date.
Within the teams I can sort in alphabetical order by name of a player, and by dates as well. The sorting works on those fields.
The issue is when I try to sort by player number it sorts the following way.
Assume we have players 1 through 30.
The ascending order in my grid will be:
1 10 11 12 13 14 15 16 17 18 19 2 20 21 etc.
Apparently for some reason it only compares the first digits but then between the teens it knows which ones come first (?).
I want the numbers sorted in a logical ascended order:
1 2 3 4 5 6 7 8 9 10 11 12 ... 20 21 22 ... 29 30
I am using ExtJS 3.3.1 grouping view in grid. The data for the grid store is coming from java objects and all the fields are strings.
Thanks!
Strings always sort this way in js. Try "2" > "10"
in the console. You have to use a number type field on the model or the store. Like this:
fields: [
{name: '...', type: 'int'}
]
When doing Array sort functions, use parseInt(...)
to convert to numbers first.