5 Replies Latest reply on Jan 23, 2008 11:01 PM by Sreenivas R

    DataGrid display problem (was WebService: nested return object)

      I am invoking a web service which works fine.
      resultFormat = "object"

      the event.result = an ArrayCollection, it has two ObjectProxys wrapping the actual objects.
      I can check them in the debugger - the values are as expected.


      PersonName - also wrapped in ObjectProxy

      The DataGrid will corectly display the dataField="personId".
      It displays dataField="name" as '[object Object]'
      It displays dataField="name.first" as blank.

      Am I navigating this incorrectly?
      Will it not navigate complex data types?
      Now do I get to the name?

      Does resultFormat="object" of the WebService not work?
      Must I use resultFormat="e4x"? If so, how do I navigate into that?

      (using FlexBuilder 3)
        • 1. Re: WebService: nested return object
          bshirley Level 1
          I can pare it down as far as this, which removes the WebService from the equation:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" >

          <mx:Model id="testModel">

          import mx.collections.ArrayCollection;

          private function find():void {
          var persons:ArrayCollection = new ArrayCollection();
          grid.dataProvider = persons;


          <mx:Button label="fill grid with one item" id="searchButton" click="find()"/>

          <mx:DataGrid id="grid">
          <mx:DataGridColumn headerText="Column 1" dataField="partyId"/>
          <mx:DataGridColumn headerText="Column 2" dataField="name"/>
          <mx:DataGridColumn headerText="Column 3" dataField="name.firstName"/>

          <mx:TextArea id="returnText" text="{grid.dataProvider.toString()}"/>

          • 2. Re: DataGrid display problem (was WebService: nested return object)
            bshirley Level 1
            I don't know if this is the solution or the workaround, but it does the trick (in a LOT more space than i wanted)...

            <mx:DataGridColumn headerText="Name Id" >
            <mx:Text text="{data.name.personNameId}" />
            <mx:DataGridColumn headerText="Name" >
            <mx:Text text="{data.name.lastName}, {data.name.firstName}" />
            • 3. Re: DataGrid display problem (was WebService: nested return object)
              ntsiii Level 3
              dataField will not accept an expression (except for @attr), and the reference must point to a value tht can be shown as a string, so to use dataField the data must be first level properties of the item object.

              To access nested data you can use a labelFunction(), somewhat simpler than a custom renderer.

              • 4. Re: DataGrid display problem (was WebService: nested return object)
                bshirley Level 1
                Thanks ntsii, labelFunction is a better solution.


                private function personName(item:Object, column:DataGridColumn):String {
                return item.name.firstName + " " +
                private function personNameId(item:Object, column:DataGridColumn):String {
                return item.name.personNameId;

                <mx:DataGrid id="grid" width="100%" dataProvider="{personAccess.findPerson.lastResult}">
                <mx:DataGridColumn id="pid" headerText="Party Id" dataField="partyId"/>
                <mx:DataGridColumn id="nid" headerText="Name Id" labelFunction="personNameId" />
                <mx:DataGridColumn id="nm" headerText="Name" labelFunction="personName" />

                • 5. Re: DataGrid display problem (was WebService: nested return object)
                  Sreenivas R Adobe Employee
                  I posted another solution here. This involves extending DGColumn. This is easy to use and has the advantage of being reusable in many places without having to have a labelFunction for each column.