开发者

Flex AdvancedDataGrid HierarchicalData XML results in unwanted rows

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_R开发者_如何学Cep="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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜