0

I guess the best way to explain my issue is to describe it in terms of the hierarchical XML data example on Livedocs.

Here, the XML is of the form

<Region Region="Arizona">
    <Territory_Rep Territory_Rep="Barbara Jennings" Actual="38865" Estimate="40000"/>
    <Territory_Rep Territory_Rep="Dana Binn" Actual="29885" Estimate="30000"/>
</Region>

However, the data I have is more like:

<Region Region="Arizona">
    <Territory_Rep Territory_Rep="Barbara Jennings">
        <Actual>38865</Actual>
        <Estimate>40000</Estimate>
    </Territory_Rep>
    <Territory_Rep Territory_Rep="Dana Binn">
        <Actual>29885</Actual>
        <Estimate>30000</Estimate>
    </Territory_Rep>
</Region>

And I would programmatically create the columns like so:

var cols:Array = [];

var adgColumn:AdvancedDataGridColumn = new AdvancedDataGridColumn();
adgColumn.headerText = "Rep Name";
adgColumn.dataField  = "@Territory_Rep";
cols.push(adgColumn);

adgColumn = new AdvancedDataGridColumn();
adgColumn.headerText = "Actual";
adgColumn.dataField  = "Actual";
cols.push(adgColumn);

adgColumn = new AdvancedDataGridColumn();
adgColumn.headerText = "Estimate";
adgColumn.dataField  = "Estimate";
cols.push(adgColumn);

grid.columns = cols;    
grid.validateNow();

However, this would result in the reps appearing as branch nodes (i.e. folders), with some empty leaf nodes underneath. This is clearly not what I want - I need it to still look as it does in the example.

Obviously I could solve this by writing some code - the simplest ways being to change the XML (be that at source, or with a parser in my Flex app), or to parse it then dump the required data into an ArrayCollection instead, but is there no way to get this to work out of the box? Given I've instructed the AdvancedDataGrid to use all the child elements on a single row, why can't it then ignore them from a hierarchy point of view?

Since the AdvancedDataGrid seems to have a few other annoying issues (e.g. question 3517769) is my best bet simply to create my own class that does everything I want it to? Or are there some decent workarounds that I'm not aware of?

Cheers.

Community
  • 1
  • 1
Marc
  • 104
  • 1
  • 10

1 Answers1

0

I think this behaviour makes sense as effectively you have another level of hierarchy by structuring your XML as you do. So the cleanest solution would be to change that, or if you prefer it that way maybe to introduce a property to mark a branch as non-hierachial like this:

<Region Region="Arizona">
    <Territory_Rep Territory_Rep="Barbara Jennings" NonHierarchial="true">
        <Actual>38865</Actual>
        <Estimate>40000</Estimate>
    </Territory_Rep>
    <Territory_Rep Territory_Rep="Dana Binn" NonHierarchial="true">
        <Actual>29885</Actual>
        <Estimate>30000</Estimate>
    </Territory_Rep>
</Region>

and overriding the parsing method of the AdvancedDataGrid to look for this property.

Edit: you might be able to work around this playing with properties like childrenField in HierarchicalData object, dig around in the documentation a bit! See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/HierarchicalData.html#childrenField

dain
  • 6,475
  • 1
  • 38
  • 47
  • Thanks. I've already considered both those solutions - amongst others - but was hopeful that I might be missing something simple. I agree that the behaviour makes sense, but it's a shame it can't be overriden by a property. Likewise the 'collapsing on refresh' issue. Looks like I'm extending/rewriting/overriding after all... – Marc Mar 31 '11 at 11:50
  • Definitely try to extend and override first before rewriting from scratch, much easier to just tune this existing grid rather than realising all the pitfalls of implementing one. Actually just found found something, editing my answer in a sec! – dain Mar 31 '11 at 12:10
  • Thanks again. I'd already explored your other suggestion too, but it's not a perfect fit for my implementation; the way I described it above is a very simplified example of what I'm actually doing. As I say, it's a shame that all this stuff isn't configurable out of the box; source XML is sometimes set in stone, after all. And the fact that the nodes collapse on refresh is just plain rubbish. Ah well, extending the class it is... – Marc Mar 31 '11 at 12:20