2 Replies Latest reply on May 24, 2010 12:41 AM by Niranjan_swain

    Refresh Or Empty datagrid

    Jayagopal Flex

      Hi,

            I have a datagrid i need to empty it. I have an arraycollection and i reallocated the datagrid with that datagrid but it doesn't work for me

      Here is the sample code

      arrcpt=new ArrayCollection();

      dggrid.dataProvider=arrcpt;

        • 1. Re: Refresh Or Empty datagrid
          Sree_D Level 2

          You can try using enableAutoUpdate or refresh properties in ICollectionView if grid is to be refreshed after data is chnaged. If only one item is chnaged or updated in sourcedata the itemUpdated method is to be called below.

           

          ICollectionView(myGrid.dataProvider).itemUpdated( event.item, myGrid.columns[event.columnIndex].dataField );

           

           

           

           

           

           

          OR

           

          ICollectionView(myGrid.dataProvider).Refresh();

           

          OR

           

          ICollectionView(myGrid.dataProvider).enableAutoUpdate = true;

           

          Let me know if this is helpful.

          1 person found this helpful
          • 2. Re: Refresh Or Empty datagrid
            Niranjan_swain

            hi

             

            actually when u want to remove the data from the data grid u have to vacant the data from ur dataprovider.

             

            in ur case if u once create the objet of arraycollection no need to crea this object again.

            there is a property removeAll() properties in array collection

            just use it,

            see following i give a example

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application

             

             

            xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

             

            <mx:Script>

            <![CDATA[

             

             

            import mx.collections.ArrayCollection;

            [

            Bindable]

             

            private var gridData:ArrayCollection = new ArrayCollection([{col1:'abc', col2:'def', col3:'xyz'},

            {col1:123, col2:456, col3:789}]);

             

             

            private function removeData():void

            {

            gridData.removeAll();

            gridData.refresh();

            }

            ]]>

            </mx:Script>

             

             

            <mx:DataGrid dataProvider="{gridData}" x="70.5" y="84">

             

             

            <mx:columns>

             

             

            <mx:DataGridColumn headerText="Column 1" dataField="col1"/>

             

             

            <mx:DataGridColumn headerText="Column 2" dataField="col2"/>

             

             

            <mx:DataGridColumn headerText="Column 3" dataField="col3"/>

             

             

            </mx:columns>

             

            </mx:DataGrid>

             

            <mx:Button x="160" y="274" label="clearedata" click="removeData()"/>

             

            </mx:Application>

             

             

            I tnik this example will help u.

            if u get sucess then please give me mark.

             

            Thanks

            Niranjan