data change in datagrid through adding listener

data change in datagrid through adding listener

Postby haretu » Wed Mar 23, 2011 9:29 am

Adobe flex.

The sample shows how to detect data change in datagrid through adding CollectionEvent.COLLECTION_CHANGE listener
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="DataGrid_collectionChange_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.CollectionEvent;

            private function init():void {
                dataGrid.addEventListener(CollectionEvent.COLLECTION_CHANGE, dataGrid_collectionChange);
            }

            private function btn_click(evt:MouseEvent):void {
                var fontArr:Array = Font.enumerateFonts(true);
                dataGrid.dataProvider = fontArr.sortOn("fontName");
            }

            private function dataGrid_collectionChange(evt:CollectionEvent):void {
                Alert.show("The DataGrid control's data provider has changed.", evt.type);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button id="btn"
                label="Click me to set DataGrid data provider"
                click="btn_click(event);" />
    </mx:ApplicationControlBar>

    <mx:DataGrid id="dataGrid"
            width="400" />

</mx:Application>
haretu
 
Posts: 132
Joined: Sat Jan 08, 2011 9:56 pm

Return to Adobe FLEX Flash

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron