1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
    teedev is on a distinguished road

      0  

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

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Answers
    3542
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    If you really needed to get the store (not sure why) you could get the store off the record.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
    teedev is on a distinguished road

      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
    Düsseldorf, Germany
    Posts
    585
    Answers
    34
    Vote Rating
    32
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default


    Ext.getStore('storeName')

  6. #5
    Sencha User
    Join Date
    May 2011
    Posts
    48
    Answers
    1
    Vote Rating
    1
    teedev is on a distinguished road

      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
    Düsseldorf, Germany
    Posts
    585
    Answers
    34
    Vote Rating
    32
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default


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

Thread Participants: 2