Results 1 to 5 of 5

Thread: change store dynamically for a tree panel

  1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106
    Answers
    1

    Default change store dynamically for a tree panel

    In my application, I would like to provide two stores for one tree panel.
    When user click a button on the tbar, the tree panel will show another store.
    I wonder if it's possible to change the store dynamically for a tree panel.

    Thanks in advance!

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

    Default

    Why not just load the store new the new data?

    Scott.

  3. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106
    Answers
    1

    Default

    scottmartin, thanks for the reply.
    But it seems doesn't work for me.
    See the example below.
    Code:
    Ext.define('myTreePanel', {
        extend : 'Ext.tree.Panel',  
        initComponent : function() {
            var me = this;
            me.store = Ext.getStore('store1');        
            me.tools = [ 
            {
                tooltip : 'change store',
                handler : function(event, target, owner, tool) {
                    me.store = Ext.getStore('store2');
                }
            }];
            me.callParent(arguments);
        }
    });
    When I click the button, the tree doesn't show store2.
    Can I just call
    Code:
     me.store = Ext.getStore('store2');
    to change store dynamically for a tree panel ?

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106
    Answers
    1

    Default

    Ext.util.Bindable provides bindStore. It works fine when I use itemselector.
    My itemselector is able to change store dynamically by using bindStore.
    But treePanel doesn't inherite from Ext.util.Bindable.
    How can I make treePanel possible to bind another store?

    Best,
    cwtuan

  5. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106
    Answers
    1

    Default

    The new version is below.

    Code:
    Ext.define('myTreePanel', {
        extend : 'Ext.tree.Panel',  
        initComponent : function() {
            var me = this;
            me.store = Ext.getStore('store1');        
            me.tools = [ 
            {
                tooltip : 'change store',
                handler : function(event, target, owner, tool) {
                    // me.store = Ext.getStore('store2'); // -> this doesn't work
                me.setRootNode(Ext.getStore('store2').getRootNode());
                }
            }];
            me.callParent(arguments);
        }
    });
    The first store will be replaced with second one. And the tree shows correctly.
    But When I expand the nodes, firebug show error message

    Code:
    records[i] is undefined
    ns[i].viewRecordId = records[i].internalId;
    It seems that the index in tree structure is broken.

    PS: I make sure the nodes in store1 and store2 has unique id.

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
  •