PDA

View Full Version : Populating several grids from a single ajax request



daltenhof
4 May 2011, 6:37 AM
Hi this is a bit of a newbie question, but I'm having trouble getting started ...

I'd like to populate several stores from a single json ajax request. Parts of the request will be split off to populate each of the four stores. The stores are connected to GridPanels.

So the question is: How do I grab only part of the ajax request and use it to dynamically populate these stores? Do I use a JsonStore or just a Store? How can one populate the stores after you've split the request into the parts needed for each store?

Thanks!

friend
4 May 2011, 6:51 AM
Each of your grids can use an Ext.data.JsonStore with autoLoad: false. In the success block of your Ajax request, you'll need to Ext.decode(response), then pluck out the child array for each grid's store and call someGrid.store.loadData(childArray).

daltenhof
4 May 2011, 10:26 AM
Yep that worked. Thanks!


Ext.Ajax.request({
url : 'MyServlet.evt' ,
scope: this,
method: 'POST',
success: function ( result, request ) {
var jsonData = Ext.decode(result.responseText);

this.tabPanelRef.outboundRef.store.loadData(jsonData.data[0].outboundBeans);
this.tabPanelRef.inboundRef.store.loadData(jsonData.data[0].inboundBeans);
this.tabPanelRef.anotherRef.store.loadData(jsonData.data[0].anotherBeans);
this.tabPanelRef.aNewRef.store.loadData(jsonData.data[0].aNewBeans);

},
failure: function ( result, request) {
Ext.MessageBox.alert('Error, unable to load data');
}
});