• Home
  • Products
  • Technology
  • Experience
  • Services
  • Our Company
  • Blog

Archives

  • February 2009
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • August 2007

Categories

  • Adobe AIR
  • Adobe Flex
  • Cairngorm
  • Encryption
  • General
  • Printing
  • UndoRedo Framework
  • Bookmarks

    • Adobe Labs
    • Planet Ubuntu

Log in
On Sorting, Betas, and Flex 3.0

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.

Posted by Aaron Leavitt on December 21, 2007 at 4:24 pm
4 Comments or LinksAdobe Flex
  1. 1
    jking
    February 19, 2008 at 11:32 am

    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.

  2. 2
    Alistair Robson
    May 18, 2008 at 1:50 am

    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”).

  3. 3
    Alistair Robson
    May 19, 2008 at 10:27 am

    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.

  4. 4
    Aaron Leavitt
    May 19, 2008 at 10:39 am

    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