2 Replies Latest reply on Oct 25, 2007 11:23 PM by Ivascu Cristian

    Populating DataGrid

    Agent_96
      Ok, it seems simple enough, I must have missed something.

      I have a datagrid where the data is provided by a remote object (Spring controlled). The code is as follows:

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

      <mx:RemoteObject id="ro" destination="userService"/>

      <mx:DataGrid right="63.5" bottom="95" left="63.5" top="96" dataProvider="{ro.getUserByDept(1)}" id="table1">
      <mx:columns>
      <mx:DataGridColumn dataField="firstName"/>
      <mx:DataGridColumn dataField="lastName"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>


      I can debug the server side code ad see that the method to retrieve the User object array is called (twice for some reason). I can see that the getFirstName() and getLastName() method on the user objects are called, but my grid is not populated with data. Why would this be?
        • 1. Re: Populating DataGrid
          rfrishbe Level 3
          getUserByDept(1) is the call to the server, but that particular function doesn't actually return the results because the command is asynchronous. Instead, you need to use a result handler to listen for when the callback returns, or do something like:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="ro.getUserByDept(1)">

          <mx:RemoteObject id="ro" destination="userService"/>

          <mx:DataGrid right="63.5" bottom="95" left="63.5" top="96" dataProvider="{ro.lastResult}" id="table1">
          <mx:columns>
          <mx:DataGridColumn dataField="firstName"/>
          <mx:DataGridColumn dataField="lastName"/>
          </mx:columns>
          </mx:DataGrid>

          </mx:Application>

          Where you bind to the lastResult (not sure if syntax is 100% right) and you call the method in the applicationComplete() listener.
          • 2. Re: Populating DataGrid
            Ivascu Cristian Level 1
            Hi Guys,

            rfrishbe is right. Calls made to a RPC service (be it webservice, httpservice or remoteobject) is asynchronous and as such it either need to use an event handler and update the dataprovider value with the received results, or bing the dataprovider to the lastResult property and when the remote object method is called, the dataprovider will be updated.

            Hope this helps,
            Cristian