labelfunction is how I would do it.

 

But note: "custom label function for each column" Since you have the entire 
item Object and know which column is being processed, a single labelFunction 
will work for multiple columns.

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Andrea 
Santambrogio
Sent: Sunday, May 27, 2007 8:33 PM
To: [email protected]
Subject: Re: [flexcoders] DataGrid and complex types

 

 

On 27/05/2007, at 21:57, André Rodrigues Pena wrote:

        

        
        Although when I try to populate de DataGrid, I can't set a
        DataGridColumn to display the property "name" within the property
        "product" from the data provider. The code is the following:
        
        <mx:DataGrid id="datagrid" dataProvider="{sales}" width="100%" 
height="100%">
        <mx:columns>
        <mx:DataGridColumn dataField="id" headerText="Id"/>
        <mx:DataGridColumn dataField="product.name" headerText="Product"/>
        <mx:DataGridColumn dataField="customer.name" headerText="Customer"/>
        </mx:columns>
        </mx:DataGrid>
        
        Only the simple attribute "id" is properly displayed in the DataGrid
        
        Why? What can I do?
        
        

        .

        
        
        

 

The way I solved it was by using a custom label function for each column. 
Instead of specifying a dataField, you define the following function inside a 
script tag:

 

function myCustomDataLabelFunction(item:Object, column:DataGridColumn):String

{

            return item.product.name;

}

 

Then you declare the column like this:

 

<mx:DataGridColumn labelFunction="myCustomDataLabelFunction" 
headerText="Product"/>

 

Basically, your label function gets invoked on each item, when the column needs 
to know what to display on that row. And you have to return the value you want 
to be displayed.

 

I hope this helped,

Andrea.

 

 

Reply via email to