PDA

View Full Version : Grid store with Memory proxy calling asynchronous function from 3rd party API



jottinger
17 Dec 2014, 4:16 PM
I've been trying to work through a problem with populating a grid with data. I am using a memory proxy with a function that contains an asynchronous third-party API call to get the data.

The data returned by my function is formatted correctly:


returnArray={
"total":1200,
"data":{
{"id":1,"value":"blah"},
{"id":2,"value":"blah blah"}
etc....
}
}


Here is the code for my store and model:


Ext.define('result.Model',{
extend:'Ext.data.Model',
fields:['id','value']
});
resultStore=Ext.create('Ext.data.Store',{
model:'result.Model',
pageSize:30,
proxy:{
type:'memory',
enablePaging:true,
reader:{type:'json',root:'data',totalProperty:'total'}
},
listeners:{
beforeload:function(store,operation,eOpts){
var page = operation.page;
var limit = operation.limit;
var returnData=getResults(page,limit);
store.proxy.data=returnData;
}
}
});


My getResults function queries an ARCGIS using their API to get data from a geospatial database. The query is asynchronous, and by the time I get the data back, it fails to populate the
store.proxy.data=returnData; portion of my code.

Here are the steps that I've combined in different ways to try getting this working:

including the 'store' in my getResults() function, and populating the store.proxy.data after my data is received.
suspending events first, then resuming the events once I have data.
calling store.sync() in my store's "load" listener.
calling store.load() (this populates my grid with data, and paging appears to work, but I end up in an infinite loop.
calling store.loadData and populating the grid directly (works but paging doesn't update)

Any recommendations?

lumberjack
19 Dec 2014, 6:21 AM
What does the definition of your getResults() method look like?

A better setup might be something similar to what's demonstrated in the fiddle below.

Regards,
Brian

https://fiddle.sencha.com/#fiddle/fbv
fbv