Flex 4 -- Call function when dataprovider changes

3.8k views Asked by At

How can I set a function to be called when the length of a DataProvider changes?

3

There are 3 answers

4
Dunaril On BEST ANSWER

Here is a good solution using the event "CollectionEvent.COLLECTION_CHANGE" :

http://blog.flexexamples.com/2008/12/16/detecting-when-the-data-provider-of-a-datagrid-control-changes-in-flex/

0
Shakakai On

If you're working with an ICollectionView (aka ArrayCollection), you could add an event listener for the "collectionChange" event.

Docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ListCollectionView.html#event:collectionChange

If you are inside an MXML document the dataProvider property of the UI component should be a source of data binding. So you could just {myComponent.dataProvider.length} bind the value to something else if that is the use case.

0
FlexCoder On

The only way I could get thru it was making a binding in the actionscript code. Something like this:

protected function creationCompleteHandler(event:FlexEvent):void {
    BindingUtils.bindSetter(myHandleFunction, myList, "dataProvider");
}

myHandleFunction receives by parameter an object with the type of the binded property.