1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    31
    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
    St. Louis, MO
    Posts
    34,107
    Vote Rating
    453
    Answers
    3157
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      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
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    31
    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
    249
    Vote Rating
    4
    Answers
    3
    Kurt001 is on a distinguished road

      0  

    Default


    Ext.getStore('storeName')

  6. #5
    Sencha User
    Join Date
    May 2011
    Posts
    31
    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
    249
    Vote Rating
    4
    Answers
    3
    Kurt001 is on a distinguished road

      0  

    Default


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