PDA

View Full Version : How to add context menu to a treepanel



bobestjs
22 Oct 2010, 3:25 PM
Hello,

Does anyone have a code example that shows how to add a context menu to the nodes on a treepanel

I've been looking all over and can't find one

thanks

Markj
22 Oct 2010, 10:52 PM
Hi


new Ext.tree.TreePanel({
title: 'My TreePanel',
root: new Ext.tree.AsyncTreeNode({
text: 'The Root',
children: [
{ text: 'Child node 1', leaf: true },
{ text: 'Child node 2', leaf: true }
]
}),
contextMenu: new Ext.menu.Menu({
items: [{
id: 'delete-node',
text: 'Delete Node'
}],
listeners: {
itemclick: function(item) {
switch (item.id) {
case 'delete-node':
var n = item.parentMenu.contextNode;
if (n.parentNode) {
n.remove();
}
break;
}
}
}
}),
listeners: {
contextmenu: function(node, e) {
// Register the context node with the menu so that a Menu Item's handler function can access
// it via its parentMenu property.
node.select();
var c = node.getOwnerTree().contextMenu;
c.contextNode = node;
c.showAt(e.getXY());
}
}
});

I have taken this form http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel under Public Event ContextMenu