javascript - In ExtJS, how do I load a store when I display a grid? - Stack Overflow

In ExtJS, how do I load a store when I display a grid? I want the store to load only when the grid is d

In ExtJS, how do I load a store when I display a grid? I want the store to load only when the grid is displayed (the user clicks on a button to show the grid, so it's wasteful to load the store beforehand). I tried the afterrender listener but it renders the loadmask in the wrong location, and the afterlayout listener reloads the grid every time the grid is resized.

In ExtJS, how do I load a store when I display a grid? I want the store to load only when the grid is displayed (the user clicks on a button to show the grid, so it's wasteful to load the store beforehand). I tried the afterrender listener but it renders the loadmask in the wrong location, and the afterlayout listener reloads the grid every time the grid is resized.

Share Improve this question edited Feb 10, 2010 at 9:50 Daniel T. asked Feb 10, 2010 at 9:29 Daniel T.Daniel T. 38.4k37 gold badges144 silver badges207 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14

This is one of those things that can be a bit of a pain to accomplish because were giving the browser too much to do at once (particularly noticeable in IE).

I like to use a combination of defer to let the browser recover long enough to render things properly.

var grid = new Ext.grid.GridPanel({
    ...,
    listeners : {
       render : function(grid){      
           grid.body.mask('Loading...');
           var store = grid.getStore();
           store.load.defer(100, store);
       },
       delay: 200
    }
});

Playing with the value of delay/defer should give you the desired results. The length of time you will need to delay/defer is dependent upon how complex your Grid is and how fast the browser is.

Also remember to remove the mask when your Store's load has completed.

listeners: {
    load: function(){
        yourGrid.body.unmask();
    }
}

NOTE: Just a few clarifications to the answer by Lloyd - you do not need to set autoLoad to false, because that is the default (ie: don't set it at all) and it sounds like from your description that you would want to use the Stores load method, instead of reload.

Have you considered handling activate event? You can add an event handler that loads data on activate event and then removes itself.

this.on('activate', function(){
 this.un('activate', arguments.callee);
    this.store.load();
}, this);

Here this refers to GridPanel.

You can set autoLoad to false for the store and just call store.reload(); when the user clicks on the button to show the grid.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1738720744a4071322.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信