Results 1 to 6 of 6

Thread: How to access a store from a groupFn and from an XTemplate?

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: How to access a store from a groupFn and from an XTemplate?

    Hi,
    I have defined a store with a groupTpl and a grouper. I want to access the store inside of both. How to do this? I know it has to do with the scope. But how? Thanks!

    Code:
    Ext.define('MyApp.store.Demo', {
      extend : 'Ext.data.Store',  
    
      config : {
        model : 'MyApp.model.Demo',
        autoLoad : false,
    
        groupTpl : new Ext.XTemplate('<div>{section:this.getGroupScore}</div>', {
          getGroupScore : function(section) {
            var store = this; //<-- "this" is not the store. How to get it?
            //...
            return 'test';
          }
        }),
    
        grouper : {
          groupFn : function(record) {
            var store = this; //<-- "this" is not the store. How to get it?
            //...
            return record.data;
          }
        }
    
      }
    });

  2. Ext.getStore('storeName')

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Answers
    3931
    Vote Rating
    1271
      0  

    Default

    If you really needed to get the store (not sure why) you could get the store off the record.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
      0  

    Default

    you could get the store off the record.
    How is this possible in getGroupScore() ? Please see my code. In groupFn() there is a parameter called record. But in getGroupScore() we don't have it.

    Thanks!

  5. #4
    Sencha User
    Join Date
    Feb 2011
    Location
    Dsseldorf, Germany
    Posts
    594
    Answers
    35
    Vote Rating
    33
      0  

    Default

    Ext.getStore('storeName')

  6. #5
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by Kurt001 View Post
    Ext.getStore('storeName')
    Thanks. Is this the only solution? My function is called for every record. If I have 1000 records Ext.getStore would get called 1000 times. I thinks that this gives not the best performance.

  7. #6
    Sencha User
    Join Date
    Feb 2011
    Location
    Dsseldorf, Germany
    Posts
    594
    Answers
    35
    Vote Rating
    33
      0  

    Default

    I took the time for 1000 items and there is no time difference.
    Should be safe to use.

Posting Permissions

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