views:

523

answers:

1

im trying to display content of xmllistcollection in different fields in my datagrid however unless i use an itemrenderer the value is not displaying in the grid.

the xmllistcollection is populated from a webservice call. Inside my item renderer i use a custom namesspace to retrieve contents from the xmllistcollection

value.ns::firstName

however if i try something like dataField = "ns::firstName" in the datagrid without using an item renderer i get no data output.

Can anyone help me out?

+2  A: 

Use the labelFunction property.

<mx:DataGrid dataProvider="{xml.ns::user}">
    <mx:columns>
     <mx:DataGridColumn labelFunction="nameLabelFunc" headerText="Name"/>
     <mx:DataGridColumn labelFunction="ageLabelFunc" headerText="Age"/>
    </mx:columns>
</mx:DataGrid>
<mx:XML source="data.xml" id="xml"/>
<mx:Script>
    <![CDATA[
     import mx.controls.dataGridClasses.DataGridColumn;
     private var ns:Namespace = new Namespace("http://www.adobe.com");
     public function nameLabelFunc(item:Object, col:DataGridColumn):String
     {
      return item.ns::name;
     }
     public function ageLabelFunc(item:Object, col:DataGridColumn):String
     {
      return item.ns::age;
     }
    ]]>
</mx:Script>

data.xml

<userInfo xmlns="http://www.adobe.com"&gt;
  <user>
    <name>John</name>
    <age>34</age>
  </user>
  <user>
    <name>Gessy</name>
    <age>32</age>
  </user>
</userInfo>
Amarghosh
great, thank you.
combi001