I have a datagrid with data like this:
Column1 Column2
1 10
2 11
3 10
4 10
When clicking Column2 and using Default Sort,the datagrid turns into this:
Column1 Column2
3 10
1 10
4 10
2 11
Why's that?I suppose it should be:
Column1 Column2
1 10
3 10
4 10
2 11
What's wrong with default sorting?Could anyone tell me how to fix it?
Thanks!
This is an interesting question. I looked into it and found that in the end
Array.sortOn()
function is getting called. In the description of that function there's a line saying:Having no way to look into the code, I would make an educated guess that the choice of not keeping the previous order of the items is dictated by the efficiency cost of it, and no real reason to keep the order in most cases. And that's the behavior the default 1 column sorting reflects.
In your case, a quick and dirty (as it's a saturday :) ) example of how to get the result you want. Your datagrid:
The sort function: