I love the new AdvancedDataGrid for Flex 3.0, it can do multiple column sorts, group my data and provide a tree view, among other amazing things. My problems began when I wanted to handle sorting of multiple properties in my own in code. The short version is that you need to apply the sort to the dataProvider property of the grid, not to your GroupingCollection. That does work, but I dug into it a bit more to find out, at least partly, why it worked.
Some background before I go on. The application I’m building uses the AdvancedDataGrid for grouping, but doesn’t show the header for the grid, so user initiated sorting is out. So I started trying to sort programmatically. The obvious thing to do would be to apply a sort to the GroupingCollection that I was using as a dataProvider, unfortunately there’s no sort property for that. After doing some searching on the internet it looked like possibly sorting the initial ArrayCollection before grouping would provide the solution, and it did, sort of. Any groups I made came out sorted correctly, including sub-groups. The items in those groups, though, were not sorted. Tracing and debugging gave me no answers, I was stuck. I finally filed a bug report, convinced it had to be a bug. The solution they gave me applied the sort to the dataProvider, and it worked.
I couldn’t just leave it there though, I needed to know what the difference was, so I dug into the Flex source code. Looking at the source for the AdvancedDataGrid, and specifically the getter and setter for the dataProvider, I saw references to IHierarchicalData and IHierarchicalCollectionView. IHierarchicalCollectionView does have a sort property, bingo! An identity comparison between my original GroupingCollection came back false, then I tried the following:
trace(myGrid.dataProvider is IHierarchicalCollectionView);
//returns true
So somewhere along the line my collection was converted/wrapped/changed so that it fit that new interface. Mind you I get pretty turned around trying to follow some of the internal code, but what it comes right down to is that applying the sort there works because the dataProvider isn’t the same collection anymore. Now if we could just get that documented somewhere. That’s the fun of working on beta software though, isn’t it? I’d love to hear if anyone else has insight on this, or cares about it for that matter.
Thanks dude! GroupingCollection was killing me because of this missing ‘Sort’ property. Thanks for logging your find regarding the undocumented ‘IHierarchicalCollectionView’ conversion. It saved me further futility.
Hi,
Am I missing the point? I am still unable to get the GroupingCollection itself to sort. So if my GroupingCollection has three elements (eg “Assets”, “Equity”, “Liabilities”) I want to be able to nominate what order the elements appear in. currently they always appear in alphabetical order ie(“Assets”, “Liabilities”, “Equity”).
Actually I was the missing the point a bit. However I solved my problem by using the GroupingFunction property of the GroupingCollection. The GroupingCollection was made on the column that defined the sort order for the collection item, and the GroupingFunction then placed the element name that I wanted (in this case Assets, Liabilities etc) into the GroupingCollection.
Glad you got it sorted out Alistair, sorting with a GroupingCollection is not something to be undertaken by the faint of heart.
Incoming Links
Trackback this post | Subscribe to the comments via RSS Feed