PDA

View Full Version : How to load ExtJS Ajax Request respone to a grid



aryanet
11 Jun 2012, 6:07 AM
I have created an app with Sencha Architect. There is a query form and it works by an Ajax.request to send the data and get the reply. It works fine but I don't know how to populate the grid with the data just replied back by the server. I tried to fire an event in the success function in Ext.Ajax.request and then in the controller handle the rest, but it didn't work and says fireEvent is not defined.
What's the solution?

scottmartin
11 Jun 2012, 7:11 AM
Have a look at store.loadData().

Regards,
Scott.

aryanet
11 Jun 2012, 7:46 AM
But I don't have access to my store. This is the piece of code I want to access the store:


items: [
{
xtype: 'button',
handler: function(button, event) {
var queryform = this.up('form').getForm();
if(queryform.isValid())
{
Ext.Ajax.request({
url: 'customers/', // where you wanna post
success: function(response){
var mystore = getCustomerDataStoreStore;
mystore.loadData(response);
},
jsonData : Ext.JSON.encode(queryform.getValues())
});
}
},
allowDepress: false,
enableToggle: false,
pressed: false,
text: 'Submit'
},


It says that getCustomerDataStoreStore is undefined. My store name is 'CustomerDataStore'.
I want to emphasize one more time that I am using Sencha Architect.

scottmartin
11 Jun 2012, 8:21 AM
You do not have qualifier on your call

var mystore = getCustomerDataStoreStore();

// psuedo example


handler: function(button, event) {
var me = this; // controller, etc.
Ext.Ajax.request({
success: function(response){
var mystore = me.getCustomerDataStoreStore();
}
});


Scott.

aryanet
11 Jun 2012, 8:36 AM
Ok, I did that as same as you said. Now it gives me the following error:
me.getCustomerDataStoreStore is not a function

I have also declared the store in my view by this:

stores: [
'CustomerDataStore'
],

But it doesn't work!

scottmartin
11 Jun 2012, 8:46 AM
This was just and example, as me = this is based on your particular setup.

You may want to review this article:
http://www.sencha.com/learn/the-mvc-application-architecture/

You can also use:
var store = Ext.data.StoreManager.lookup('myStore');

Scott.