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

    DataGrid change handler

      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:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Type" dataField="type"/>

      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


          2. Add an event listener for myEvent

          addEventListener("myEvent", myEventListener);

          3. every time the arraycollection is updated dispatch the event 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

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