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

    DataGrid display problem (was WebService: nested return object)

    bshirley
      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.

      Person
      personId:long
      name:PersonName

      PersonName - also wrapped in ObjectProxy
      first:String
      last:String

      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">
          <root>
          <partyId>123</partyId>
          <name>
          <firstName>Bob</firstName>
          <lastName>Jones</lastName>
          </name>
          </root>
          </mx:Model>

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;

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

          ]]>
          </mx:Script>


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

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

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


          </mx:Application>
          • 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:itemRenderer>
            <mx:Component>
            <mx:Text text="{data.name.personNameId}" />
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Name" >
            <mx:itemRenderer>
            <mx:Component>
            <mx:Text text="{data.name.lastName}, {data.name.firstName}" />
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            • 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.

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

                <mx:Script>
                <![CDATA[

                private function personName(item:Object, column:DataGridColumn):String {
                return item.name.firstName + " " +
                item.name.lastName;
                }
                private function personNameId(item:Object, column:DataGridColumn):String {
                return item.name.personNameId;
                }
                ]]>
                </mx:Script>

                <mx:DataGrid id="grid" width="100%" dataProvider="{personAccess.findPerson.lastResult}">
                <mx:columns>
                <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" />
                </mx:columns>
                </mx:DataGrid>

                • 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.

                  http://flexpearls.blogspot.com/2008/01/extending-dgcolumn-and-adgcolumn-to.html