6 Replies Latest reply on Aug 17, 2007 9:52 AM by stephan.k

    DataGrid - How to refresh / clear / empty it ?

    stephan.k Level 1
      Dear Forum

      How do I most efficiently empty and reload a DataGrid. I have tried to datagrid.removeAllColumns() function. It does seem to clear the headers but I get multiple click events, one more with every refresh, which means I must be doing something wrong with clearing the dataGrid.

      Any wise advice?

      Thanks

      SK
        • 1. Re: DataGrid - How to refresh / clear / empty it ?
          stephan.k Level 1
          oh I think I know... it must be the event listener. I keep adding the same event listener which causes the multiple redundant calls.

          How do I remove this listener in a clean way? I'm a little confused by the Delegate Syntax...

          Thanks

          SK
          • 2. Re: DataGrid - How to empty it
            Level 7
            myGrid.removeAll();

            will remove all data.

            --
            Dave -
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: DataGrid - How to empty it
              Level 7
              PS - if you're reloading the grid with new data, just setting the
              dataProvider should be all you need to do. It doesn't append to old data
              already in the grid.

              --
              Dave -
              Head Developer
              http://www.blurredistinction.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/


              • 4. Re: DataGrid - How to refresh / clear / empty it ?
                Gorka Ludlow Level 1
                To remove all the data simply give it an empty dataProvider:

                var empty:Array = new Array();
                myDG.dataProvider = empty;

                To change the content simply give it a new array as dataProvider:

                var notempty:Array = new Array();
                //fill up notempty
                myDG.dataProvider = notempty;

                Cheers,
                Gorka
                www.AquiGorka.com
                • 5. Re: DataGrid - How to refresh / clear / empty it ?
                  stephan.k Level 1
                  Thank you very much to all of you. I've tried all your suggestions but it didn't solve the problem. I am still getting more and more click (drop) events every time I am refreshing the dataGrid. I have a feeling the problem might be in the event listener? I am not quite familiar with the delegate syntax used in the addEventListener line... ?

                  Any ideas?

                  I am pasting in a little larger snippet of the code this time. Hope it's not too overwhelming. The code output looks like this. Notice that every time I drop the item (when calls the initDataGrid function), I get more and more ITEM DROPPED calls :

                  -------output--------------------------------------
                  ITEM DROPPED HEALTH SERVICES
                  ITEM DROPPED COMMUNICATIONS / TECHNOLOGY
                  ITEM DROPPED COMMUNICATIONS / TECHNOLOGY
                  : undefined category name :
                  : undefined category name :
                  ITEM DROPPED INSURANCE
                  ITEM DROPPED INSURANCE
                  ITEM DROPPED INSURANCE
                  ITEM DROPPED INSURANCE
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  ITEM DROPPED EDUCATIONAL
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  : undefined category name :
                  ----------output end-------------------------------

                  .

                  Thank you very much for any leads.

                  Best

                  SK
                  • 6. Re: DataGrid - How to refresh / clear / empty it ?
                    stephan.k Level 1
                    I know now that the event is definitely not removed properly which causes the multiple dropped calls. I've debugged it with a doOnce boolean variable. The following code works:
                    if(!doOnce){

                    doOnce=true;
                    var dgListener:Object = new Object();
                    dgListener.thisObj = this;

                    dg.removeEventListener("onDrop", this);
                    dg.addEventListener("onDrop", Delegate.create(this, itemDrop));
                    }