Results 1 to 4 of 4

Thread: [SOLVED] ExtJs 4.2 Multiple instances of the same Store

  1. #1

    Default Answered: [SOLVED] ExtJs 4.2 Multiple instances of the same Store

    Hi guys,

    My situation is as follows, I'm trying to respect the DRY and reuse the code as much as possible (if it's still readable).
    I have a grid that uses a store, and into another view I have a combo that need a read-only version of the data on the same store.

    For example: Users/Groups, on the view to display the Users you have a combo to select a Group that should use the same Store as the view (grid) that displays the Groups. So far all filtering applied to the Groups store in the grid are visible in the combo to, because stores are singletons, is there an easy way to use a new instance of the same store ?

    So far I tried to load it by hand and use something like this in the controller:

    replaced
    Code:
    store: [App.store.Groups]
    to
    Code:
    Ext.create('App.store.Groups')
    OR:
    Code:
        initComponent : function() {
            var me = this;
    
            Ext.apply(me, {
                store : me.buildStore()
            });
    
            me.callParent(arguments);
        },
    
        buildStore : function() {
            return Ext.create('App.store.Groups');
        },

    But all of my tests used the same store instance.
    Last edited by marisradu; 22 Apr 2014 at 1:03 AM. Reason: add Solved in title

  2. You could use the following:

    Code:
    Ext.define('App.store.MyStore', {
        extend : 'Ext.data.Store',
        alias  : 'store.app-mystore', // create store alias
    
        // ... 
    });    
    
    Ext.define('App.view.MyCombo', {
        extend : 'Ext.form.field.ComboBox',
        xtype  : 'app-mycombo',
    
        requires : [
            'App.store.myStore'
        ],
    
        // combo config
    
        store : {
            type : 'app-mystore' // store alias; type creates new instance
        }
    });

  3. #2
    Sencha User
    Join Date
    Mar 2011
    Location
    Hyderabad
    Posts
    106
    Answers
    10

    Default

    Create new instance of store to each component i.e for grid and combo.
    store: Ext.create('App.store.Groups');

    If you want to use the filter to grid store only, then add this on grid render

    listeners:{
    render: function (grid){
    grid.getStore().filterBy(function(record) {
    return record.get("name") == 'A';
    });
    }
    }

  4. #3
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    You could use the following:

    Code:
    Ext.define('App.store.MyStore', {
        extend : 'Ext.data.Store',
        alias  : 'store.app-mystore', // create store alias
    
        // ... 
    });    
    
    Ext.define('App.view.MyCombo', {
        extend : 'Ext.form.field.ComboBox',
        xtype  : 'app-mycombo',
    
        requires : [
            'App.store.myStore'
        ],
    
        // combo config
    
        store : {
            type : 'app-mystore' // store alias; type creates new instance
        }
    });

  5. #4

    Default Solved

    Sorry for the late answer, this solve the problem.
    I had to set the store.autoLoad to true otherwise the combo will not trigger it's load() method.

    Thank you.

Tags for this Thread

Posting Permissions

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