8 Replies Latest reply on May 25, 2006 3:18 AM by ckshah

    How to clear a data grid?

    Kwooda
      How do I clear a data grid control?
        • 1. Re: How to clear a data grid?
          TIPLVinay Level 1
          Do the following
          DataProvider="";
          • 2. Re: How to clear a data grid?
            Kwooda Level 1
            By doing that, doesn't that effectively disassociate the data grid from a data provider? Isn't there a method available anywhere, say on the interface of the data provider, to clear the dataset? I may have a data provider that is retrieving different sets of data based on search parameters - I just want to clear the results in preparation for a clean start for a new search, not break the connection between the data grid and the data provider.
            • 3. Re: How to clear a data grid?
              TIPLVinay Level 1
              Can u explain wht exactly u want 2 do?
              • 4. Re: How to clear a data grid?
                Level 7
                you want
                datagrid.removeAll()

                "TIPLVinay" <webforumsuser@macromedia.com> wrote in message
                news:e3ej23$526$1@forums.macromedia.com...
                > Can u explain wht exactly u want 2 do?
                >


                • 5. Re: How to clear a data grid?
                  Kwooda Level 1
                  TPILVinay - I have a data grid with some data displayed in it. I also have a button labelled "Clear". When clicking on the clear button, I want the data to go away.

                  bodrul - removeAll() is an undefined method, according to the FlexBuilder 2.0 Beta 2 compiler.
                  • 6. Re: How to clear a data grid?
                    TIPLVinay Level 1
                    Take this Sceniro,

                    Declare an object as

                    1) var dgObject: Object;

                    dgObject=dataService.Result;

                    2) dg.dataprovider=dgObject;
                    or
                    <mx ataGrid ...... .. dataProvider="{dgObject}"


                    Now on click action of " clear Button"
                    dgObject="";
                    it will clear your dg.


                    Also if u assign the different dataservices search results (see 1) to dgObject ,then data displayed will automatically changes(give accurate results) for each search.

                    if u r looking for a inbuild method to clear a datagrid,i hv no idea about it
                    • 7. How to clear a data grid?
                      Kwooda Level 1
                      Actually, as it turns out, bodrul had the solution I was looking for, I just didn't have my bindings set up appropriately. What I wound up doing was declaring an ArrayCollection variable and binding that as the data provider to my grid. Then the results of the HTTPService request gets placed into the ArrayCollection variable. When I want to clear the grid, all I do is call the removeAll() method on my ArrayCollection variable - no need to break the connection between the grid and the data provider. Whenever the HTTPService request (or whatever I bind my ArrayCollection variable to in the future) gets called again, the table is populated with the new results.

                      OK I just re-read your example and I see you are basically saying the same thing. For some reason I was thinking you were setting the dataProvider attribute to "". But I've got it, now. Thanks!
                      • 8. Re: How to clear a data grid?
                        ckshah Level 1
                        hi,
                        in flex2.0 beta2 and beta3 version u have to collect data httprequest data into arraycollection. this way

                        <mx:HTTPService id="srv" url="catalog.xml" useProxy="false"
                        result="employeesOrg = new ArrayCollection(srv.lastResult.catalog.product)"/>
                        <mx:script>
                        import mx.collections.ArrayCollection;
                        import mx.collections.IList;
                        [Bindable]
                        public var employeesOrg:IList= new ArrayCollection();

                        </mx:script>

                        u can clear array every time before u bind it with datagrid this way

                        employeesOrg.removeAll();

                        and add item in array this way

                        employeesOrg.addItem( {name: 'ttt', price: '0.5'} );

                        and also bind this array to datagrid this way

                        <mx ataGrid id="destgrid" width="100%" x="4" y="205" dataProvider="{employeesOrg}">
                        <mx:columns>
                        <mx:Array>
                        <mx ataGridColumn dataField="name" headerText="Name" width="140"/>
                        <mx ataGridColumn dataField="price" headerText="Price" width="80"/>
                        </mx:Array>
                        </mx:columns>
                        </mx ataGrid>

                        this way u can bind data

                        tracy