PDA

View Full Version : change store dynamically for a tree panel



cwtuan
26 Jun 2012, 8:44 AM
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!

scottmartin
27 Jun 2012, 9:22 AM
Why not just load the store new the new data?

Scott.

cwtuan
28 Jun 2012, 5:49 AM
scottmartin, thanks for the reply.
But it seems doesn't work for me.
See the example below.


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

me.store = Ext.getStore('store2'); to change store dynamically for a tree panel ?

cwtuan
28 Jun 2012, 6:11 AM
Ext.util.Bindable provides bindStore (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.util.Bindable-method-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

cwtuan
28 Jun 2012, 6:22 PM
The new version is below.



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



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.