2 Replies Latest reply on Mar 11, 2008 11:14 AM by bof1

    DataGrid change handler

    bof1
      I have a DataGrid object which is populated via a dataProvider (which is an ArrayCollection in the model). It works fine -- grid is updated whenever underlying data is updated.

      BUT I need to invoke a function when the data in the grid is updated by the dataProvider. I tried to attach a "dataChange" event handler to the DataGrid, but the function is never called.

      <mx:DataGrid id="dgresults" dataProvider="{model.searchResults}" dataChange="searchResultsChanged(event)" >
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Type" dataField="type"/>
      </mx:columns>
      </mx:DataGrid>

      Any ideas? Have tried any number of alternatives ... no luck. I'm sure it's very obvious to somebody out there ...HELP!
        • 1. Re: DataGrid change handler
          Gaurav J Adobe Employee
          1. Instead of making your arraycollection [Bindable] make it bindable for a specific event type

          [Bindable("myEvent")]

          2. Add an event listener for myEvent

          addEventListener("myEvent", myEventListener);

          3. every time the arraycollection is updated dispatch the event myEvent

          dispatchEvent("myEvent");

          4. in the eventlistener from step #2

          assign the arraycollection to data provider of data grid and invoke your desired function?

          private function myEventListener(event:Event):void {
          dgresults.dataProvider = model.searchResults;
          //call your function here
          }

          Thanks,
          Gaurav
          • 2. Re: DataGrid change handler
            bof1 Level 1
            Thanks Gaurav!.... The approach you selected worked for what I needed to do.