PDA

View Full Version : How do you focus on the first child of a tree



Yemi
2 Aug 2013, 12:51 AM
I have a treepanel with one root node and a child node. How do you focus on the child node when the application loads the first time ( I mean to automatically select/click on that node). Thanks

wm003
2 Aug 2013, 1:01 AM
Try


MyTreePanel.getRootNode().childNodes[0].select();

Yemi
2 Aug 2013, 1:32 AM
Ideally that should work. This is what the root node looks like, I put this code render listener class of the treepanel
this.getRootNode().childNodes[0]. printing this to the console says it is undefined.

here is the the content of the root of the treepanel, but still did not work.



var root2 = { text : 'root',

expanded : true,
iconCls:'icon-folder_normal',
children : [{

text : 'child1',
expanded:false,

}
]



}

Yemi
5 Aug 2013, 12:46 AM
can anyone help with this ?

slemmon
5 Aug 2013, 8:40 AM
Does this example help?



var tree = new Ext.tree.TreePanel({
renderTo: document.body,
useArrows: true,
autoScroll: true,
animate: true,
containerScroll: true,
border: false,


root: {
text: 'root',
expanded: true,
iconCls: 'icon-folder_normal',
children: [{
text: 'child1',
expanded: false,
}]
},


listeners: {
afterrender: function () {
this.getRootNode().firstChild.select();
}
}
});

Yemi
19 Aug 2013, 8:30 AM
Thanks, worked well.