Hello,
I have three list grid controls in my application. Every control have bounded to a data source. I want use the data come from these controls in a RPCManager (send them to server side and do some calculations then return the result).
First, I created three list grid controls.
isc.ListGrid.create({
ID:"list1",
dataSource:ds1,
//...
});
isc.ListGrid.create({
ID:"list2",
dataSource:ds2,
//...
});
isc.ListGrid.create({
ID:"list3",
dataSource:ds3,
//...
});
Then, I used a RPCManager to invoke a server side page.
list1.fetchData();
list2.fetchData();
list3.fetchData({},function(){
isc.RPCManager.sendRequest({
callback:function(data){...},
data:[list1.somedata,list2.somedata,list3.somedata],
actionURL:"/process.jsp"
});
});
I know that fetchData method is asynchronous so we don’t know when the result will return. Yes, we can use fetchData({},callback) to assign a callback function to wait the invocation complete.
My problem is that how can I ensure the list1 and list2 have completed the fetching data process when use RPCManager that will refer the these two controls data?
Hi Landofdreams,
I don’t fully understand your application’s pattern, but from your description, it sounds like you need to perform a fetch on 3 databound grids, and then fire some logic when all 3 fetches have returned.
You can do this by having the callback methods from all 3 fetch calls call a single notification function which will track which grids’ fetches have returned.
Once the third fetch has returned, the notification method can continue with your other logic.
So something like this:
var grids = ["list1", "list2", "list3"];
function fetchReturned(listGrid) {
grids.remove(listGrid);
if (grids.length > 0) return;
// ... continue with other logic since all three fetches have returned.
}
list1.fetchData(null, "fetchReturned(this.getID())");
list2.fetchData(null, "fetchReturned(this.getID())");
list3.fetchData(null, "fetchReturned(this.getID())");
Another approach for this, if you’re using a SmartClient server integration is to queue your fetches up and fire them all at once.
You’d do this by calling isc.RPCManager.startQueue() before calling ‘fetchData()’ on each list, then calling isc.RPCManager.sendQueue() to send the fetches to the server. This ensures that all 3 fetches are processed in a single HTTP turnaround, and will be processed in order.
You can then hang your callback logic on the last of the 3 fetchData() calls. When it fires, all three listGrids should have been populated with data.
Thanks for your reply
You have understood my question and gave me an excellent solution.
Thanks a lot!