PDA

View Full Version : Controlling store events



catacaustic
18 Aug 2011, 5:28 PM
I've been trying to get a custom grid filter to work, but I can't figure out how to get the values to filter from into the stores parameters. So far in my controller I have:

this.control ({
"store": {
beforeload: function (store, op, opt) {
store.getProxy ().extraParams = {
stuff: "goes in here"
};
}
}
});
I realise that I'm probalby doing this wrong, at least with the wrong selector, but this doesn't do anything, so I've tried a lot of other selectors, but I'm not coming up with anything that's working so far. Is there some "easy" way to handle the events of a store from my controller?

slemmon
18 Aug 2011, 10:20 PM
I've had the same question. I was looking for some sort of addParams sort of method to do this for me and didn't find it. I did have success doing what you're doing, though. I did a store.getProxy().extraParams = {object} and that worked for me.

I found on a forum response or two that the best way to load parameters dynamically is like so:
store.load({params: {stuff: 'goes_here'}})

That will send any extraParams you have set up in your proxy + whatever you just sent on the fly. So, it won't wipe out any extraParams you have set. I believe the idea is that load({params: {}}) is for your dynamic params and extraParams are always sent - a static set.

I'm not sure I'm in love with the setup and honestly had someone not answered this one on the forums for me and I were left to figure out how to do this from the API docs I'm afraid I'd still be lost. Not sure if that speaks to a deficiency in the docs, me, or both.

No need to point fingers, right? :)

catacaustic
18 Aug 2011, 10:29 PM
Thanks, but I've got the store.getProxy ().extraParams = {} part already in my code.

What I need to know is how to get the reference to the store. The store is attached to a GridPanel that's a child of the main panel, but I can't work out the selector.

slemmon
18 Aug 2011, 10:56 PM
Oh, I see what you're saying. That is a great question. 'Cuz a store isn't necessarily owned by a widget at a given time, but I would think could still be loaded (although I'm having trouble with that very concept presently).

I'll preface this by saying I don't love my answer - feels a little hacky.

I tried using a selector of '*' and listening for any load events - nothing. Which makes me thing there is no store selector you could use.

I set up a relayEvents for load on my grid that I use my store on and then used 'gridpanel' as my selector and it caught the load event that way.

Maybe there's a way for the store to fire an application event and have your controller listen for it? I've fired application events from a controller, but not right from a store/widget and am not sure how to do that (how to grab a reference to an owning controller/application, that is).

So, all I got is relaying the load event to an owning widget. That said, works as long as you have a widget you want to have be the owner of that relay.

catacaustic
19 Aug 2011, 3:18 AM
I thought about an application event myself, but I just believe that's overkill for what I want to do. This should be a simpe thing to od, but it's proving to be a huge issue. How does everyone else try to configure store vents when you've got 50-100 stores to look after? I know that I'm going to have at least 50, and could get up into the hundreds when I'm finihed, and I really don't like the idea of having ot fire off application events for all of those when the MVC model should provide an easier, and better, way of doing that.

So, is there anyone out there that can help??? :-/

raz0r1
19 Aug 2011, 4:03 AM
I had the same problem and asked some time ago without getting an answer from anyone so i think there is no perfect way.

To have a similar way like the selection i created an extra store controller that loads only the stores and then i added via

this.getStore('Storename').on();
in the init() mehtod.

i hope there is a better way but until now i dont find one.

mitchellsimoens
19 Aug 2011, 6:12 AM
The problem with Controllers in their current state is that the control call takes in ComponentQuery strings... Stores aren't Components, they are Classes. We are figuring out a more workable solution but for now you can get your Store and use the 'on' method.

catacaustic
20 Aug 2011, 4:32 PM
Hopefully something can be done to address this soon. I can understand that getting a store is "hard" becaue it's not a component but it does seem like that's a big chunk of what would normally be standard functionality that's just been passed over. Maybe in the next release there wil be something that can give that sort of functionality?

Justin Noel
18 Dec 2012, 7:05 AM
The problem with Controllers in their current state is that the control call takes in ComponentQuery strings... Stores aren't Components, they are Classes. We are figuring out a more workable solution but for now you can get your Store and use the 'on' method.

Any new solution?