PDA

View Full Version : Best Place To Call Store.load()?



matt_d_rat
27 Jun 2011, 7:07 AM
I was wondering whether someone would be able to answer when the best time is to call store.load()?

I have my app set up in an MVC structure, and have a Ext.Panel which contains an Ext.List. When I dispatch a call to my controller I render my panel and on activate, I load the store (as I have to pass a dynamic value to an extraParam filter to return a subset of results).

This all works fine and loads the data as expected. However when I drill down into my records and then return back to the list view, the load is called again (as you would expect). I ideally don't want this to happen if I am simply navigating back to the list from a record within that list. But I do need to reload the list each time I dispatch the call to load the containing panel.

Any advice?

bclinton
27 Jun 2011, 7:37 AM
There doesn't seem to be any kind of store.isLoaded() method but there is a store.getCount() so one thing you could try is checking the item count of your store in your activate handler like this:


listeners: {
activate: function (c)
{
// load store on activate if not already loaded
var store = c.getStore();
if (store.getCount() <= 0)
{
store.load();
}
},

Of course if your count is zero (correctly) then it will keep reloading on activate, but you may be able to live with that.

matt_d_rat
28 Jun 2011, 12:23 AM
Thanks for your reply bclinton. I'll give this a try and see if it works for what I am trying to do.