Skip to main content
Known Participant
August 16, 2007
Question

DataGrid - How to refresh / clear / empty it ?

  • August 16, 2007
  • 5 replies
  • 438 views
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
This topic has been closed for replies.

5 replies

stephan_kAuthor
Known Participant
August 17, 2007
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));
}
Inspiring
August 17, 2007
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
stephan_kAuthor
Known Participant
August 17, 2007
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
Inspiring
August 17, 2007
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/


Inspiring
August 17, 2007
myGrid.removeAll();

will remove all data.

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


stephan_kAuthor
Known Participant
August 17, 2007
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