View Full Version : What the best way to manange stores on a form

22 Nov 2007, 2:35 PM
I have 5 stores that are the values of combo boxes on my form

The form itself has a store the loads the current record. Sometimes the combo boxes haven't got all their data back before the record is loaded and the combo renders with 'unknown value' instead of the proper value.

how do I ensure that all 'lookup' stores are loaded first before I load the record store?

this.stores['MaritalStatusType'] = Ext.StoreMgr.get('MaritalStatusType');
this.stores['GenderType'] = Ext.StoreMgr.get('GenderType');
this.stores['Nationality'] = Ext.StoreMgr.get('Nationality');
this.stores['RelationshipType'] = Ext.StoreMgr.get('RelationshipType');
this.stores['StatusType'] = Ext.StoreMgr.get('StatusType');

// blah blah blah



22 Nov 2007, 2:56 PM
You could add a defer() to the record.load or call the record.load from a handler of the last combo's load event.

22 Nov 2007, 4:08 PM
is there a tutorial on using defer() I can't seem to pick up how it is used after reading the api doco.

are you suggesting this kind of thing for the other method...I haven't tested this yet but it looks ironclad.

this.stores['StatusType'].on('load', function(){this.store.load();}, this);
this.stores['RelationshipType'].on('load', function(){this.stores['StatusType'].load();}, this);
this.stores['Nationality'].on('load', function(){this.stores['RelationshipType'].load();}, this);
this.stores['GenderType'].on('load', function(){this.stores['Nationality'].load();}, this);
this.stores['MaritalStatusType'].on('load', function(){this.stores['GenderType'].load();}, this);


22 Nov 2007, 4:39 PM
To defer a call, you could do

store.load.defer(500, scope, args)
Any args you would normally pass to the original function go in the args to defer function. There are some uses of this scatttered thru the examples.

As for the 2nd way, you necessarily have to chain them all - that's going to force them to run 1 at a time and could be a performance issue. You could call all 5 in a row and probably come up with some way of setting flags in the load handlers as they complete. Then in the dependant store's beforeload event, check the flags in some type of polling loop til they're all set.

Obviously that adds more complexity and forces that store to know about all the other ones. I would try the defer way 1st.

22 Nov 2007, 4:47 PM
Ok thanks for the help. I'll try both and see which one works best for me.

with the defer is this the kind of thing you are talking about

store.load.defer(500, this, {

callback: function(){
var task = {
run: function(){
// do counter check and react in some way
interval: 500



22 Nov 2007, 5:24 PM
I don't think you need to do a defer and a task. Either just defer the load for a period of time or you could just put that task in the a beforeload handler for the store.

22 Nov 2007, 6:00 PM
OK, that makes more sense, thanks...

I have been playing with the second method and sometimes (maybe 1 in 20) the last load event doesn't fire...weird.