View Full Version : Avoid error loading a store binded with a destroyed grid.

19 Feb 2010, 8:23 AM
I know that what I will describe is probably poor designed, but it is my first ExtJS application.

I have a panel (panel A) in which I load the content of a view page or the content of an edit page depending on the panel state. The view page will show the information, while the edit page will allow to edit the data.

The edit page contains javascript code that creates a JsonStore calling the load method on it. Then, a GridPanel associated with that store is rendered inside panel A. There is a button that allow the user to revert to the view page, destroying the GridPanel. If the user clicks it before the JsonStore.load method has returned, I am getting an error. I suppose that's because when the load method returns, the code tries to interact with a destroyed component.

Is there any way of cancelling a load operation on a JsonStore if its associated grid doesn't exist anymore?

Browser: IE 6


19 Feb 2010, 8:51 AM
A global variable or some other property that you set in your store's load handler (for when the load has completed)..

Then if the user clicks the button, in that button's handler, you'd see

if global variable isn't set yet
then store hasn't finished loading so we shouldn't execute code

you could even popup a messagebox or set a statusbar to notify the user of their impending doom :)


19 Feb 2010, 10:13 AM
I have thinked of a similar solution... disabling the button until the load has completed, but I want a non-blocking solution, if possible! :)

23 Feb 2010, 11:26 AM
I really need an answer to this... I am a little desperate to find a solution now!

23 Feb 2010, 11:55 AM
Instead of destroying components on the view switch, why don't you use a CardLayout and just switch the visible panel?

25 Feb 2010, 8:49 AM
....Just toggle .style.display on the .dom object:

yourDiv.dom.style.display = 'none';

yourDiv.dom.style.display = ''; // etc to display again

there's no reason to be messing with CardLayouts and other heavy set components unless you're positive you need it.

Use the DOM to your advantage. Make some divs and just switch which ones are displayed. Easy as pie.

26 Feb 2010, 9:02 AM
My mistake, I wasn't destroying the grig properly. It works fine without errors now, because the destroy() is purging all listeners so nothing's happening when the store fires the load event.

Thanks for your advices.