Results 1 to 4 of 4

Thread: Gird store onload fired multiple times (updated)?

  1. #1
    Sencha User
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    65

    Default Gird store onload fired multiple times (updated)?

    (not sure why my previous posts didnt get publish at all, trying again)

    Considering the same grid :

    PHP Code:
    Ext.ns('Test.grid');

    Test.grid.searchGrid Ext.extend(Ext.grid.GridPanel, {
        
    titleTest',
        initComponent: function() {
            var config = {
                id: '
    searchgrid',
                title : '
    Data',
                hidden : true,
                frame:true,
                store: this.buildStore(),

    };
            Ext.apply(this, Ext.apply(this.initialConfig, config));
            Test.grid.searchGrid.superclass.initComponent.apply(this, arguments);
            },

    buildStore : function(){
                 return new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy(callRequest({
                            service : "TestRecord"
                        })),
                         reader: new Ext.data.JsonReader({
                             totalProperty: '
    count',
                             root : '
    record',
                          fields:  [
                                 {name:'
    acctId'},
                                {name: '
    prdTyp'},
                                ]
                         }),

                         listeners: {
                            load: function(store,record,options)
                                {
                                    alert("called from listener");
                                }
                            } 
                    }); 
    // the below loadGrid is called from another js file as Ext.getCmp('
    searchGrid').loadGrid(test)
     loadGrid : function(data){
                 this.store.load({
                     params:{
                     start:data,
                     limit:10
                   }
                });
                 this.store.on('
    load', function() {
                     alert("called from outside");
                 });
                 
            }
                } 
    What i am seeing is, if i call the loadGrid() function multiple times from the other panel js file which hosts this grid,
    i see the alert("called from outside"); call being called multiple times. i.e for the first time when i call, i see the alert coming up one time,
    the next time when i call the loadGrid, i see the alert coming up 2 times.

    But this doesnt happen with the alert which is present under the store listener, the alert present there is only called once, no matter how many time i load the store.

    Can you please help what is going on here.
    In the broader extent, i am reaching to the point that, my complex code running after on-load event in the loadGrid, i may have to move it under listener.
    But just wanted to know the reasoning behind this phenomena,

    Please advise,

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    You are registering a new load handler every time you call the function.

    You want:
    Code:
    this.store.load({
      params:{
        start:data,
        limit:10
      },
      callback: function(){
        alert('I am only called after this load is complete');
      }
    });
    or
    Code:
    this.store.on('load', function() {
      alert("This handler is removed after being called");
    }, this.store, {single: true});

  3. #3
    Sencha User
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    65

    Default

    Thanks Condor,
    That makes perfect sense.
    Will always keep this in mind from now on.
    But how does callback() differs from this.store.onLoad event ?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Callback is called after the load event (can be useful sometimes) and it also called for failed loads (which would trigger the exception event).

Similar Threads

  1. [Please IGNORE] store onLoad being called multiple times inside grid?
    By duskandawn in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 14 Sep 2010, 6:56 PM
  2. 'load' event fired multiple times..?
    By Thrinath in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 26 Oct 2009, 6:25 AM
  3. Mouse events fired multiple times
    By Glimpse in forum Ext GWT: Discussion
    Replies: 5
    Last Post: 23 Sep 2009, 8:16 AM

Posting Permissions

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