8 Replies Latest reply on May 28, 2010 7:41 PM by Miggl

    Flex MX:TREE based on GroupingCollection2 datasource?

    Miggl

      I have an ArrayCollection that consists of VO objects derived from a database query. I have grouped this collection of objects using the GroupingCollection2 object, but cannot for the life of me figure out how to bind it correctly to my tree control. It only displays [object GrouingCollection2] in the tree container, but not the objects contained within the GroupingCollection2 object. Any idea on what I might be doing wrong?

       

      Thanks!

        • 1. Re: Flex MX:TREE based on GroupingCollection2 datasource?
          Flex harUI Adobe Employee

          You may need a custom ITreeDataDescriptor.  Tree probably can't handle

          GroupingCollections by default.  This might help.

           

          http://blogs.adobe.com/aharui/2008/12/tree_and_lazy_or_paged_data_1.html

          1 person found this helpful
          • 2. Re: Flex MX:TREE based on GroupingCollection2 datasource?
            Sameer Bhatt Adobe Employee

            Also, you can fetch the grouped data from GroupingCollection and assign that to the Tree control. For example -

             

                     <mx:Script>
                      <![CDATA[
                           protected function button1_clickHandler(event:MouseEvent):void
                           {
                                        gc.refresh();
                                        tree.dataProvider = gc.getRoot();
                           }
                      ]]>
                 </mx:Script>
            
                 <mx:GroupingCollection2 id="gc">
                      <mx:source>
                           <mx:ArrayCollection>
                                <mx:Object day="1" hour="1" Skill0="1"/>
                                <mx:Object day="1" hour="2" Skill0="1.5"/>
                                <mx:Object day="1" hour="3" Skill0=".25"/>
                           </mx:ArrayCollection>
                      </mx:source>
                      <mx:grouping>
                           <mx:Grouping label="day">
                                <mx:GroupingField name="day" />
                           </mx:Grouping>
                      </mx:grouping>
                 </mx:GroupingCollection2>
                 
                 <mx:Tree labelField="day" id="tree" width="200" />
                 <mx:Button label="Group" click="button1_clickHandler(event)" />
            
            • 3. Re: Flex MX:TREE based on GroupingCollection2 datasource?
              Miggl Level 1

              Thanks FlexHarUI and Sameer,

               

              I will look into your custom tree descriptor post and see if that is what I need.

               

              I was able to figure out that my original problem with GroupingCollection2 was that I didn't call getRoot(), but didn't post about it, since it didn't meet my original needs. It appears that GroupingCollection only creates a two-dimensional hierarchy, but not n-level nested hierarchies (which is what I need).

               

              I have categories that have a parent category specified. Those categories whos parent_id is null or 0 are top-level categories. I have so far been unable to find a single example that uses hierarchical data from a database. All examples I have seen use XML data or manually constructed ArrayCollections.

               

              How do I build a hierarchical ArrayCollection that consists of value objects? My head feels like I have scrambled eggs for brains by now .

               

              Thanks for any help you can provide.

               

              ~Mike

              • 4. Re: Flex MX:TREE based on GroupingCollection2 datasource?
                Miggl Level 1

                Hi HarUI,

                 

                You custom data descriptor got me on the right path. I am able to get my arraycollection to display properly in the tree control.

                 

                Not sure if this should be in a separate topic or not, but it is closely related to this issue as well:

                 

                Is there an efficient way to convert a nested dataset query result into a nested ArrayCollection of my object (that implement the custom data descriptor)?

                 

                As of now I am writting custom code for it to parse the query result array and build a nested ArrayCollection from scratch. Wouldn't FLEX be smart enough to recognize nested data and return it as a nested ArrayCollection?

                 

                Thanks again!

                • 5. Re: Flex MX:TREE based on GroupingCollection2 datasource?
                  Flex harUI Adobe Employee

                  Flex doesn't have an official concept of nested arraycollections.  The

                  custom data descriptor's job is to created a nested arraycollection

                  on-demand so you don't have to process the whole thing upfront.

                   

                  The key is to cache any arraycollection you create so you re-use the same

                  collection for a particular set of children.

                  1 person found this helpful
                  • 6. Re: Flex MX:TREE based on GroupingCollection2 datasource?
                    Miggl Level 1

                    Thanks for the helpful info. Can you point me to a tutorial, or documentation that explains how to accomplish this in-depth? It seems that this problem is written about much in books on Flex, nor on most web sites I have been googling.

                     

                    Thanks again!

                    • 7. Re: Flex MX:TREE based on GroupingCollection2 datasource?
                      Flex harUI Adobe Employee

                      The source for the default datadescriptor does caching using a Dictionary.

                      • 8. Re: Flex MX:TREE based on GroupingCollection2 datasource?
                        Miggl Level 1

                        Thanks for the pointer. Gotta be honest with you, though: still confused as to what to do. In one hand I have the DefaultDataDescriptor, on the other my ValueObject. Now I'm missing the glue: how to make the two work together?

                         

                        All the books I have on Flex (O'Reilly Flex 3 Programming, Flex 3 in Action) don't go over this topic.

                         

                        I've read posts online that recommend that I extend my VO with the DefaultDataDescriptor, but couldn't find anywhere that explains how to use it properly. For a newbie the ASDoc reads a bit confusing.

                         

                        Any suggestions as to where I can read up more on this?

                         

                        Thanks!