4 Replies Latest reply on Oct 23, 2006 1:19 AM by ljonny18

    refresh dataGrid View

    ljonny18 Level 1
      Hi

      I am having trouble when deleting a row from my dataGrid and then renewing the view within the dataGrid after the row has been deleted (removing the row from the dataGrid) – refreshing the dataGrid results???


      I am using a dataGrid to display data from coming from a webService called (wsData)…..
      When a row of the dataGrid is selected, the row ID is set relevant to the selected (relevant) row.
      Beneath the dataGrid I have a “delete” button which when selected calls a function that deletes the row relevant to the seleted ID etc…. :


      <Script….>
      [Bindable]
      public var selectedID:String = new String;
      [Bindable]
      public var populateDGsObj:Object = new Object;

      public function init()
      {
      populateDGsObj.status = “all”;
      wsData.getOPGList.send(populateDGsObj);
      }

      public function handleWSR(event:ResultEvent):void
      {
      myDG.dataProvider = event.result;
      }


      public function dgRowSelect()
      {
      selectedID = MyDG.selectedItem.id;
      }

      public function deleteRow()
      {
      if (myDG.selectedIndex >= 0)
      {
      Alert.show("Are you sure…?", "Delete Row", 3, this, function(event:CloseEvent):void
      {
      if (event.detail==Alert.YES)
      {
      wsData.deleteOPG.send(selectedID);
      }
      });
      }
      }
      </Script>

      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:mi="components.*" creationComplete="init()">

      <mx:WebService id="wsData" wsdl=http://...?wsdl>
      <mx:operation name="getRes" result="handleWSR(event)"/>
      </mx:WebService>

      <mx:DataGrid id="myDG" change="dgRowSelect()">
      <mx:columns>
      <mx:DataGridColumn id="a" dataField="a" headerText="A"/>
      <mx:DataGridColumn id="b" dataField="b" headerText="B"/>
      <mx:DataGridColumn id="c" dataField="c" headerText="C"/>
      <mx:DataGridColumn id="d" dataField="d" headerText="D"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Button id="delButt" label="Delete" click="deleteRow()"/>

      etc…………………..


      This all works fine… when the button is selected, the relevant ID is taken and passed into the delete function, and passed to the webService, and the row is successfully deleted!

      My problem is then the dataGrid view… the row is still shown (remains) in the dataGrid, thus I assume the view needs to somehow be “refreshed” but I am unsure of the best way to go about doing this…
      I have tried calling a function after the delete call is sent to the webService that recalls the original DataGrid DataProvider webService results… e.g…:


      public function deleteRow()
      {
      if (myDG.selectedIndex >= 0)
      {
      Alert.show("Are you sure…?", "Delete Row", 3, this, function(event:CloseEvent):void
      {
      if (event.detail==Alert.YES)
      {
      wsData.deleteOPG.send(selectedID);

      init();
      }
      });
      }
      }


      but this works 50% of the time as I assume it is running at the same time as the “delete” function, and depending on which finishes first – will alter is the “deleted” row is displayed etc…..

      Anyway – in summary, I was just wondering if anyone could offer any help, and let me know the best way to go about deleting my record and renewing the view within the dataGrid relevant to the row being deleted…?

      Thanks,
      Jon.
        • 1. Re: refresh dataGrid View
          leotemp Level 1
          Maybe try:

          public function handleWSR(event:ResultEvent):void
          {
          myDG.dataProvider = event.lastResult;
          }
          "lastResult" will allways be the latest result from your dataprovider, so when it changes so shall your component using it.
          • 2. Re: refresh dataGrid View
            ljonny18 Level 1
            hi thanks for your post, but when I use the "event.lastResult" I get the following error:

            1119: Access of possibly undefined property lastResult through a reference with static type mx.rpc.events:ResultEvent.

            any suggestions?

            thanks,
            Jon.
            • 3. Re: refresh dataGrid View
              ntsiii Level 3
              event.result is correct.

              Define a result handler function for the deleteOPG operation.

              Call the getRes.send() in tht handler.

              Tracy
              • 4. Re: refresh dataGrid View
                ljonny18 Level 1
                Ok... but I am a little confused (sorry to be a nuisance ),

                my delete function within my webService requires an ID to be passed from the Flex application, thus when a row is selected, the ID of the selected row is taken, so when the Delete button is pressed it sends this ID to the webService where it is taken and used - and therefore deleting the row etc.....


                Do you mean to define the result handler for the deleteOPG operation in the main webService tag, i.e. :

                <mx:WebService id="wsData" wsdl=http://...?wsdl>
                <mx:operation name="getRes" result="handleWSR(event)"/>
                <mx:operation name="deleteOPG" result="handleWSR_deleteOPG(event)"/>
                </mx:WebService>

                and then call it in my delete function, passing the ID from my delete function to my new result handler function ??? :

                Thanks,
                Jon.