views:

495

answers:

2

I need a hierarchical grid that shows data in columns for the parent rows as well as the child rows.

- a parent | 1234 | data | data |
   a child | 2222 | data | data |
   a child |  212 | data | data |

I've tried to make ADG work, but by default it has all columns except the grouping column blank for parent rows. I think I could use item renderers to push the data out there.

My blocking problem is that my grouping does not seem to work at all. I can see the data when I set dataProvider=MyArrayCollection, but

<mx:GroupingCollection id="GroupingCollection" 
           source="{this.specificReportData.gridData}">
    <mx:Grouping label="childName">
        <mx:GroupingField name="parentName" />
    </mx:Grouping>
</mx:GroupingCollection>

does not work: no data appears. I've tried having an explicit "childname" column, and not having one. I've tried wrapping it in a HierarchicalCollectionView, but that doesn't work either. I've walked through the basic grouping tutorials and my code and data look like it follows the pattern.

Any ideas?

+1  A: 

You must not include parents in your datasource. You need a datasource like this:

   a child | 2222 | data | data | parentid | parentname
   a child |  212 | data | data | parentid | parentname

And set the groupingfield to parentid or parentname. The grouping makes a hierarchy out of a flat datasource and thus creates the parents for you.

Thomas
yeah, but I have data for the parent in their own row. I think I might have to do ugly filtering in the array collection.Still, the grouping should have worked, no?
Richard Haven
I've just re-read your question. So the grouping works but you don't like the empty columns in the group rows? Perhaps summaries are what you are looking for: http://flexpearls.blogspot.com/2007/06/advanceddatagrid-summary-with-column.html
Thomas
possibly, possibly. I had actually given up on the ADG completely, but you have given me hope.Of course, now I really do need the grouping to work, which it still does not.
Richard Haven
Can you provide a sample of you dataprovider?
Thomas
A: 

The answer is that the AdvancedDataGrid is not built to do what I want.

It is great at grouping data with common values; it is not good at grouping data where the actual parent elements exist as rows themselves. I also require the sorting and filtering apply to the parent elements only (based on their own data); any visible parent can show their children, and the children never sort.

My two-stage solution is first to process the data by iterating through it and creating an array of parent elements and adding a children array property to them that holds the child elements. Note that these are arrays of references; I am not copying the actual data.

Next, I apply any sorting and filtering to the parent array (perhaps by using an ArrayCollection wrapper) and iterate through the parents, copying the visible ones (and their children if the parent is marked expanded) to a display array. My grid them uses the display array as a simple (e.g. not grouped) dataProvider. A custom item renderer will indent the children and change the expanded property of the parent elements, which will regenerate the display array.

This is not only a simpler and more intuitive solution, it does not require a reader or maintainer to understand the idiosyncrasies of ADG (my motto: No Clever Code).

Thank you Thomas for trying. I'm giving your reply a +1 even though I'm not marking it as the answer.

Cheers

Richard Haven