AdvancedDataGrid does not displays object properties
Asked Answered
A

2

6

I have following data:

var data: ArrayCollection = new ArrayCollection(
            [
                { name: "ProductA", user: {login: "loginA", email: "emailA"} },
                { name: "ProductB", user: {login: "loginB", email: "emailB"} },
                { name: "ProductC", user: {login: "loginC", email: "emailC"} }
            ]
        );

This array is a data provider for my AdvancedDataGrid:

<mx:AdvancedDataGrid dataProvider="{data}">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="Product" width="55" dataField="name" /> 
        <mx:AdvancedDataGridColumn headerText="User" dataField="user.login" />
        <mx:AdvancedDataGridColumn headerText="Email" dataField="user.email" />
    </mx:columns>
</mx:AdvancedDataGrid>

The problem is - AdvancedDataGrid does not displays properties of nested User object, but the simple DataGrid does. What's wrong here ?

Abagail answered 19/2, 2010 at 19:14 Comment(0)
I
7

You need to use a labelFunction or an itemRenderer. Here is an example of a labelFunction

<mx:AdvancedDataGridColumn headerText="User" labelFunction="getUserLogin" />

which calls

private function getUserLogin(item:Object, column:AdvancedDataGridColumn) {
  return item.user.login;
}

The item argument will be the data that your cell is receiving.

Irmine answered 19/2, 2010 at 22:20 Comment(1)
I should add that I don't really know what your object model looks like, so you should make your labelFunction, then put a breakpoint on the first statement and examine the "item" in the debugger so you can address the correct property you are looking for, wherever it is in the structure.Irmine
D
1

DataGrid was patched to support complex paths but I don't think that AdvancedDataGrid was. More details: http://bugs.adobe.com/jira/browse/SDK-9801

You can use a labelFunction instead.

Doriadorian answered 19/2, 2010 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.