PDA

View Full Version : Wait for store to load and then bind to grid



hieu79vn
6 Aug 2012, 9:28 AM
Hi

I have a store which take 5 second to load and I want to bind it to a grid after it finish loading
How can I do?

Thanks

scottmartin
6 Aug 2012, 10:04 AM
You can either load a store and use it to populate the store already bound to the grid, or use reconfigure to assign a new store.

Scott.

hieu79vn
7 Aug 2012, 2:43 AM
Thank you Scott
Could you please give me an example of this "You can either load a store and use it to populate the store already bound to the grid"?

Thank you

scottmartin
7 Aug 2012, 8:46 AM
Review the following:



// main app store
var gridStore = new Ext.data.Store({
});

// loader store for new data; append records to main
var loadStore = new Ext.data.Store({
listeners: {
'load': function(store, records, successful) {
gridStore.loadData(records,true); // append records to main
}
});


Scott.

hieu79vn
7 Aug 2012, 11:23 PM
Wow it's really good Scott. Thank you.

I have another question.
I have a grid with many records. When user inserts a new record I must reload all the grid to show the new record and it takes time. I think I can use your solution to append the new record into the old store and reload it. But I don't know how we can add the new record in the first position.
Furthermore, do you have any other solution for my problem? I saw the CRUD model, but I don't know if it helps for performance.

Merci beaucoup Scott :)

scottmartin
8 Aug 2012, 6:10 AM
You can use store.insert(0,record) .. the grid will update.. there is no need reload entire store.

Scott

hieu79vn
9 Aug 2012, 3:05 AM
Thank you Scott

hieu79vn
14 Aug 2012, 7:52 AM
Hi Scott,

I tried to do as your instruction

// main app storevar gridStore = new Ext.data.Store({}); // loader store for new data; append records to mainvar loadStore = new Ext.data.Store({ listeners: { 'load': function(store, records, successful) { gridStore.loadData(records,true); // append records to main }});
It's really good but I have one more question about the performance. The code above means that we will load data in to loadStore and when the loadStore finish loading we will put these data into gridStore. My problem is when loadStore is loading, if I do some otherrequest to server, the server cannot response immediately but it must wait for the loadStore to finishloading.Do you know how to improve the performance here?Thank you

scottmartin
14 Aug 2012, 8:10 AM
You can use store.suspendEvents/resumeEvents

Scott.

mjhaston
25 Apr 2013, 3:29 PM
Review the following:



// main app store
var gridStore = new Ext.data.Store({
});

// loader store for new data; append records to main
var loadStore = new Ext.data.Store({
listeners: {
'load': function(store, records, successful) {
gridStore.loadData(records,true); // append records to main
}
});


Scott.



I had a similar task. I'm submitting data that spits out results. I wanted to wait for the store to load and then switch to another tab in my application and select the first row, since that is bound to a form. Your idea to listen for the load event works perfectly!

I might just need to add code to make sure there is at least one record.

Thanks Scott. I wish this guy would have marked this as answered.




listeners : {
load : function() {
individualResultsGrid.getSelectionModel().select(0);
console.log('userStore load fired')
}
},