PDA

View Full Version : Loading grid data from Controller



Angron
29 May 2012, 7:50 AM
Hello,

I'm new with ExtJs4 and after trying a simple grid example I'm not sure about something.
In my example, I've got a model, a store and a controller that must refresh a simple grid.

In the controller I can get my store very easily with the auto generate function based on the store name.

So my question is, why when I get my store with the auto generated function and then make a "load()" on it, the data in my grid aren't loaded ? The only way to load the data in my grid looks like to get the grid store (the same one) and call a "load()" on it : "grid.store.load()"

Here is my example:


Ext.define('Test.controller.User', {
extend: 'Ext.app.Controller',
models: [
'Test.model.User'
],
stores: [
'Test.store.Users'
],

init: function() {
this.control({
'.userView': {
afterrender: this.reloadGrid
}
});
},

reloadGrid: function(userView) {
//This is not loading data in the grid....
var store = this.getTestUsersStore();
store.load();
//This is working...
userView.store.load();
}

});

Thx in advance :)

scottmartin
29 May 2012, 12:07 PM
We will need more information as your snippet is not enough to provide any real detail:

-Do you have the store assigned to the grid?
-Do you get a results when you call store.load()
-What does you return JSON l look like? Is it formatted properly?
-Are you using a debugger to review your header and response (Firebug / Developer Tools)
-Do you get any console errors?

Regards,
Scott.

Angron
29 May 2012, 11:04 PM
-Do you have the store assigned to the grid?
Yes

-Do you get a results when you call store.load()
Yes

-What does you return JSON l look like? Is it formatted properly?
It looks like exactly the same as the json I get when using grid.store.load(). The only difference is that the grid only refresh data when using grid.store.load().

-Are you using a debugger to review your header and response (Firebug / Developer Tools)
Yes

scottmartin
30 May 2012, 4:42 AM
Can you provide the JSON or a small working example that displays your problem? I am unable to help with the limited information as there are numerous causes for data not displaying in a grid.

Scott.

Zinnia
30 May 2012, 5:23 AM
//This is not loading data in the grid.... var store = this.getTestUsersStore(); store.load();

In the above code you are creating another instance of store.

store.load()
This will load data in current instance of store. If you want to load data in the grid panel,
you need to access the same instance of store which is used in the grid panel.so that
the data will loaded to that particular store.



Thanks
Zinnia

Angron
31 May 2012, 3:00 AM
This is what I expected Zinnia, ty for confirmation :)