Extjs 4 treepanel Reload and Expand
Question
I'm using Extjs4 treepanel with Json data.I want reload the treepanel and need expand tree menu to specified node. I'm using the following code. Please let me know how do this.
//Define tree store
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'my_tree.php',
},
noCache: false
});
// Treepanel
var treePanel = Ext.create('Ext.tree.Panel', {
id: 'mytree',
renderTo: 'tree_div',
height: 400,
bodyBorder: false,
border: false,
singleExpand: true,
rootVisible: false,
store: store,
useArrows: true
});
//Reload tree
function reload_tree(){
var tree_panel = Ext.getCmp('mytree');
tree_panel.enable();
tree_panel.getLoader().dataUrl = 'my_tree.php';
tree_panel.getLoader().load(tree_panel.root);
//Expand tree node
tree_panel.getLoader().on('load', function(loader, node){
tree_panel.getNodeById(nodeid).expand();
//here node id is tree menu nodeid
});
}
Thanks in advance
Solution
Reload the tree i think it's simpler to just call
treePanel.getStore().load();
then you can listen to the load event, so that the data is all fetched and finally from there select the desired node.
treePanel.on("load", function( treeStore, records, successful, operation)){
var id = 4; // This is the ID of the node that somehow you know in advance
var node = treeStore.getNodeById(id);
treePanel.expandPath(node.getPath());
});
HTH!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow