R – Flex datagrid component and aggregated classes

airapache-flexdatagrid

I have the following question regarding Flex/AIR data grids:

Can I access the value of a var of one aggregated object as a dataField of a column of the DataGrid?

What I would like to have is:


public class A {
public var id:String;
}


public class B {
public var a:A;
public var value:uint;
}

    <mx:DataGrid id="grid" dataProvider="{items}">
        <mx:columns>
            <mx:DataGridColumn headerText="aId" dataField="a.id"/>
            <mx:DataGridColumn headerText="value" dataField="value"/>
        </mx:columns>
    </mx:DataGrid>

items is an ArrayCollections of B's.

From what I have read and looked in the code for the DataGridColumn this 'a.id' does not work as that value is taken from the data object using the array syntax data[key], I have tried to use a custom item renderer but that did not work either.

Could I get some help with this? I am trying to figure out Flex as home project and I just started out.

Best Answer

After some more tries got the problem solved.

<mx:DataGrid id="grid" dataProvider="{items}">
    <mx:columns>
        <mx:DataGridColumn headerText="aId">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Label text="{data.a.id}"/>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn headerText="value" dataField="value"/>
    </mx:columns>
</mx:DataGrid>
Related Topic