2 Replies Latest reply on Apr 21, 2010 12:55 PM by CrazyMerlin

    Programmatic creation of parent > child GroupCollection

    CrazyMerlin

      Hey peeps!

       

      I am creating an ADG with data bound to an object who's source is from a MySQL table. In one instance the grid will display categories in a tree style expandable to show sub categories.

       

      I have been trying to get the content to display but have been having problems. Prior to adding grouping I have confirmed that the data is there, however I think the problem may ( or may not ) stem from the parnet > child linking. Each category with a "parent_id" of 0 is a category, with each sub category having a parent_id of, obviously, it's parents id value.

       

      What I was doing was creating a GroupCollection2 instance, a Grouping instance and a couple of GroupField instances, similar to this:

      code.gif

       

      The obj.Result variable is the data returned from the server in JSON format which when decoded looks like this:

      results.gif

      So you can see here the relationship between the id fields.

       

      Now obviously this doesn't work or I wouldn't be here, but I cannot pinpoint whether I am assuming too much and need to better sort my data, or whether there is a flaw in my creation of the group fields/coll etc.

       

      N.B.: I know the first image uses parent_id but the second uses cat_parent_id...not how it appears in the real code

       

      Any help greatly appreciated.

      Paul

       

      Message was edited by: CrazyMerlin because the syntax highlighting blocks destroy the code!

        • 1. Re: Programmatic creation of parent > child GroupCollection
          CrazyMerlin Level 1

          Well, it seems that I was so wrapped up in managing other bits of code that I missed

          an essential part of the column grouping: flat data. As my data is already hierachical

          I will try to use the HierarchicalCollectionView instead.

          • 2. [Solved]
            CrazyMerlin Level 1

            Ok, I solved this issue by resorting my existing data into a proper hierachy in an array collection. I then cast that array collection as a HierachicalData and set its childrenField to the property name of the sub categories as defined in the array collection. After that, setting the dataProvider property of the ADG and validating it with ADG.validateNow(), everything worked.

             

            So the problem on my part was not having my data in a hierachical form in the first place. Conceptually it was, but contextically it wasn't.

             

            Anyone who wants to see the actual solution from getting the data from MySQL to getting it into an ADG can email me at paul at webtop-designs.com and I will put up an article describing how I did it in detail.

             

            This was fun