AdvancedDataGrid hell: data on grouping rows
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?
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.
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
精彩评论