Results 1 to 10 of 10

Thread: Wait for store to load and then bind to grid

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    211

    Default Wait for store to load and then bind to grid

    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

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    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.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    211

    Default

    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

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    Review the following:

    Code:
    // 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.

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    211

    Default

    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

  6. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    You can use store.insert(0,record) .. the grid will update.. there is no need reload entire store.

    Scott

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    211

    Default

    Thank you Scott

  8. #8
    Sencha User
    Join Date
    Mar 2012
    Posts
    211

    Default

    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

  9. #9
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    You can use store.suspendEvents/resumeEvents

    Scott.

  10. #10

    Join Date
    Jan 2008
    Location
    Levittown, PA
    Posts
    364
    Answers
    2

    Default

    Quote Originally Posted by scottmartin View Post
    Review the following:

    Code:
    // 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.


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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •