3 Replies Latest reply on Jan 27, 2009 11:54 AM by Myonlycrummynick

    Inserting object data into a datagrid

    Myonlycrummynick
      Hi guys.

      I'm building a flex application getting data from at webservice. The result from the webservice looks like the coded pasted in at the buttom.

      An array of person-objects each with a single info-object inside it. All is good for the firstname and lastname part, i can use the following code - where event.result is the response from my webservice:

      var arrResult:ArrayCollection = new ArrayCollection();
      arrResult.source = event.result.toArray();
      dg1.dataProvider = arrResult;
      firstnameField.dataField = "Firstname";
      lastnameField.dataField = "Lastname";

      But what if i want to insert the phonenumber into the 3rd column called phoneField? I'd like to use:

      phoneField.dataField = "Info.Phone"; // Not working...

      but that doesn't work, i guess it's because flex does not know whether there is one or 10 info-objects inside each person-object.

      So how do i do it?

      I see i can use Person(arrResult.getItemAt(0)).Info.Phone to extract the value for a specific person-object (here the first in the result, but how do i fill in all of the for each person in the grid?

      Thanks in advance.

      /Nibby
        • 1. Re: Inserting object data into a datagrid
          Level 7

          "Myonlycrummynick" <webforumsuser@macromedia.com> wrote in message
          news:gli9f9$apq$1@forums.macromedia.com...
          > Hi guys.
          >
          > I'm building a flex application getting data from at webservice. The
          > result
          > from the webservice looks like the coded pasted in at the buttom.
          >
          > An array of person-objects each with a single info-object inside it. All
          > is
          > good for the firstname and lastname part, i can use the following code -
          > where
          > event.result is the response from my webservice:
          >
          > var arrResult:ArrayCollection = new ArrayCollection();
          > arrResult.source = event.result.toArray();
          > dg1.dataProvider = arrResult;
          > firstnameField.dataField = "Firstname";
          > lastnameField.dataField = "Lastname";
          >
          > But what if i want to insert the phonenumber into the 3rd column called
          > phoneField? I'd like to use:
          >
          > phoneField.dataField = "Info.Phone"; // Not working...

          Try labelFunction instead.

          HTH;

          Amy


          • 2. Inserting object data into a datagrid
            ntsiii Level 3
            As Amy says, labelFunction is the way to go.

            "labelField: can only take a string, which is the name of a first level property of the item. Usually an object property, or an xml attribute or an xml child node text value.

            It can *not* take an expression, like Info.Phone.
            • 3. Re: Inserting object data into a datagrid
              Myonlycrummynick Level 1
              Sorry for the late answer, you are both right on.

              For the record - i used

              phonefield.labelFunction = myLabelFunc;

              private function myLabelFunc(item:Object,column:DataGridColumn):String
              {
              if (item.Info.Phone==undefined)
              {return null;}
              else
              {return item.Info.Phone;}
              }

              Thanks guys.