PDA

View Full Version : How to *select* tree node on load?



JohnJones357
20 Mar 2014, 3:18 PM
I have two trees that share the same store and data. Tree 1 has a context menu and when an action is clicked, it passes along the node as a parameter so I am able to get the nodes id by node.data.id; where "node" is the parameter. So I am trying to set that same node as Selected in Tree 2, which is essentially the same tree with the same data i.e id's, text etc, but as a separate component. the code i have so far is:

var node_id = node.data.id;//the id of node selected in tree1
var selectedNode = this.getTree2().getStore().getNodeById(node_id);
this.getTree2().getSelectionModel().select(selectedNode);

No errors but node in tree 2 doesnt show as selected.

any help is appreciated thanks

brian428
20 Mar 2014, 3:32 PM
If you use Ext.log() or set a breakpoint just before you call select(), you'll probably find that the value of selectedNode is null. Which would mean that you're not using the correct value for the node ID.

brian428
20 Mar 2014, 3:57 PM
Quick example:

4ds

JohnJones357
21 Mar 2014, 7:31 AM
Brian,

Thanks for reply. I debugged and saw node.data.id was in fact defined, which i knew cus node.data.id is being passed in an Ajax request later on, but i saw node_id is not defined. I simply replaced node_id inside ..getNodeById(node_id) with ...getNodeById(node.data.id); and it works fine.