PDA

View Full Version : SOLVED: Ext.StoreMgr simple question



SchattenMann
25 Aug 2009, 8:13 AM
hi

Trough all the ERP i'm developing i have the need to refresh a hole group of stores on specific form groups submitting...

so i thought - and this is just an idea, feel free to give your opinion - to register all stores and then reload them when needed.

but i need to identify them so if i submitted a form "xpto" i'll go to each store associated with the "xpto" group and reload them.

the question is how...can i use storeId multiple times (i don't think so) or it has to be unique?

if no, whats the alternatives?

tks for your patient...

hendricd
25 Aug 2009, 8:22 AM
@SchattenMann -- You're on the right track. ;)

In Ext3, most all data-bound controls are Ext.StoreMgr-aware. That is, you pass the storeId of the store you wish to bind the control to (or the actual instance (reference)of the store).

Simply specify a unique storeId for each store when you declare them. When you do that, it's automatically registered with the StoreMgr.

Then Ext.StoreMgr.lookup('stateCodes').load(); would raise all the pertinent events to all controls is was bound to.

SchattenMann
25 Aug 2009, 8:34 AM
since storeId has to be unique (as it should) i suppose that i wouldn't be able to use

Then Ext.StoreMgr.lookup()

and i say that because i create the grid store on the initComponent function and without any id an to use lookup() i need the id.

so what about if i do the following:



this.store = new Ext.data.GroupingStore({
url: 'file.php',
storeId: Ext.id(),
storeGroup:'gridProcessos',
reader:new Ext.data.JsonReader({
,totalProperty:'totalCount'
,root:'rows'
,fields:[...]
})

});


and then when i need them



Ext.StoreMgr.each(function(s){

if(s.storeGroup == 'XPTO'){
s.reload();
}

})


what do you think? functional?

hendricd
25 Aug 2009, 8:40 AM
Or, perhaps let your storeId fragment help with that:



this.store = new Ext.data.GroupingStore({
url: 'file.php',
storeId: Ext.id(null, 'XPTO'),

reader:new Ext.data.JsonReader({
,totalProperty:'totalCount'
,root:'rows'
,fields:[...]
})

});
and then when i need them



Ext.StoreMgr.each(function(s){
var xptoRe = /xpto/i;
if(xptoRe.test(s.storeId)){
s.reload();
}

})


Either approach should work fine.

SchattenMann
25 Aug 2009, 8:49 AM
definitely better :D

i do think it would be great to add the storeGroup concept (like DDGroup exists for example)...

one question (that i know its not directly related):

i see that stores are not auto destroy by default so every time i open/close something they remain in the StoreMgr...so i suppose that if i set autoDestroy: true they are removed from the StoreMgr...but theres definitely some faster way to set all stores autoDestroy: true...i just don't know how :P

maybe something like Ext.data.Store.autoDestroy: true...

tks ;)

hendricd
25 Aug 2009, 8:52 AM
Ext.data.Store.prototype.autoDestroy = true;

SchattenMann
25 Aug 2009, 8:53 AM
Thank You...;)

PS: is it possible for me to post a request/suggestion?

hendricd
25 Aug 2009, 8:56 AM
If it's a Feature Request there is a Forum for that (for Premium Members). Is that what you mean?

SchattenMann
25 Aug 2009, 8:59 AM
something like that...

i see that the feature request topic is only for premium users...

but i was just trying to give a suggestion to make ExtJS better...not exactly a request...:P

maybe some Premium User have the same idea soon...;)

hendricd
25 Aug 2009, 9:10 AM
What did you have in mind?

SchattenMann
25 Aug 2009, 9:18 AM
a way of Ext Users submit they suggestions for future ExtJS features...

maybe a form to fill or something...

for example now i would suggest to add a storeGroup feature so this way we could retrieve, not a single store but an array of stores.

something like Ext.StoreMgr.groupLookup('myGroup');

this way we are easily able to do some mass-actions like

Ext.StoreMgr.groupLookup('myGroup').reload() or Ext.StoreMgr.groupLookup('myGroup').setParam()..

i think its very useful...

hendricd
25 Aug 2009, 9:42 AM
@SchattenMann -- I could see where that 'feature' might be appealing to you. But, what if another implementation needed something similar but only for stores that were already loaded once?

The Ext.StoreMgr.each iterator (as you've already seen) handles any possible grouping/filtering (of stores) scenarios one might imagine.

SchattenMann
25 Aug 2009, 9:48 AM
is indeed...

for my own use i did the following:



ERP.util.storeReload = function (string){

Ext.StoreMgr.each(function(s){
var patt = new RegExp(string);
if(patt.test(s.storeId)){
s.reload();
}
});

};
this way i simple call ERP.util.storeReload('myPrefix') and its done

appreciate your effort and its a pleasure belong to such a great community.

hope soon i can return: stop asking "how to" and start answering "do that" :P