PDA

View Full Version : treepanel on contextmenu focus item?



SlashEMc2k
22 Nov 2007, 4:13 AM
When I create a context menu off a treepanel, how do I set focus on the item?
I tried to do something like this:

Ext.get(node.ui.elNode).focus();
Ext.get(node.ui.elNode).addClass('x-tree-selected');

But this didn't work because when I clicked on another item the class remained on the item where the context menu had been.

mjoksa
22 Nov 2007, 7:27 AM
tree.expandPath(tree.getSelectionModel().getSelectedNode().getPath());
tree.selectPath(tree.getSelectionModel().getSelectedNode().getPath());

If you want, after this code, you can fire click event for selected node.

Hope this helps

SlashEMc2k
22 Nov 2007, 9:48 AM
Thanks mjoksa;




function treeContextMenu(node) {
tree.selectPath(node.getPath());
}


This worked perfectly :D
Theres one thing that I couldn't figure out; which isn't a problem.
selectPath doesn't seem to work on the root node?

nevf
22 Nov 2007, 12:02 PM
Thanks mjoksa;




function treeContextMenu(node) {
tree.selectPath(node.getPath());
}


This worked perfectly :D
Theres one thing that I couldn't figure out; which isn't a problem.
selectPath doesn't seem to work on the root node?

Do you have the Root node hidden. ie. rootVisible: false If so your actual root is root.firstChild

mxu
22 Nov 2007, 12:19 PM
iinside hnadler, add node.select() works cross-webbrowser.

onContextMenu: function(treeNode, e){
// force selection on the treenode
if(!treeNode.isSelected())
treeNode.select();
...
};

SlashEMc2k
23 Nov 2007, 2:18 AM
Thanks mxu, thats fixed everything :D