View Full Version : Call a function anytime an event of a component is triggered.

12 Aug 2009, 10:20 PM

The title might sound really confusing. Suppose I have a big EXTJS application.

What I want to do is:
- When beforewrite event of the store is triggered, show an element
- When write or exception event of the store is triggered, hide that element

I would do it manually, but I already have ~ 40 stores in the application.

Is there any way I can globally (and preferably without modifying ext-all.js) do this for all my stores?

Thanks a lot.

12 Aug 2009, 10:39 PM
When using a lot of something (stores) it's sometimes a good idea to abstract out the creation to a factory method so you can make changes easily...

This thread should help though:


12 Aug 2009, 11:20 PM
Thanks a lot! All my stores are based on Ext.Ajax. By putting this code (and defining the showel and hideel functions that show and hide that elemenet) i get exactly the desired result for any server request.

Ext.Ajax.on('beforerequest', showel, this);
Ext.Ajax.on('requestcomplete', hideel, this);
Ext.Ajax.on('requestexception', hideel, this);

You may close the topic.

13 Aug 2009, 1:15 AM
Or you could make the Store class observable, and then listen for events from that:


13 Aug 2009, 1:17 AM
Bah! Direct linking just does not work with the new doc generator!

You will have to scroll down to obvserveClass and expand it yourself.

13 Aug 2009, 3:03 AM
Thanks a lot :). At first, I made Store observable, but later I realized I needed to display a preloader even for direct ajax requests (Ext.Ajax.request). As Store is based on ajax requests, using the code I posted above solved the problem :)

13 Aug 2009, 3:12 AM
That's OK unless you configure an HttpProxy with an instance of Ext.data.Connection instead of allowing it to use the Ext.Ajax singleton.