Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Dominik Marks on Apr 21, 2008 02:59
open dhtmlx forum
Context menu show/hide completely based on tree item

Hello there,

I would like to have a context menu only for certain items in my tree. Other items should not have a context menu at all.

I successfully implemented an onShowMenuHandler, which calls "hideItem" on all menu items in the menu. It looks like this:

function isContextMenuAllowed(itemId) {
var lReadOnly = [<%=lReadOnlyArray%>];
if (lReadOnly.contains(itemId)) {
for(var i=0;i<taxonomyContextMenu.menu.itemsCount;i++)
taxonomyContextMenu.menu.hideItem(taxonomyContextMenu.menu.items[i].id);
}
else {
for(var i=0;i<taxonomyContextMenu.menu.itemsCount;i++)
taxonomyContextMenu.menu.showItem(taxonomyContextMenu.menu.items[i].id);
}
return true;
}

This works ok, but even after hiding all items from the menu, an "empty" context menu is still shown. This means, there is a small white rectangle shown at the mouse cursor position, which overlays some of the content of the page.

Is it possible to disable the context menu completely for some items in the tree?
Answer posted by Support on Apr 21, 2008 07:34
In order to set context menu only for certain items you can use any of the following methods:

1) To use setOnShowMenuHandler method  - if handler function returns false, the menu will not be shown:

 aMenu.setOnShowMenuHandler(onShowMenu)
            
function onShowMenu(treeitemId){
    if(tree.getLevel(treeitemId)!=1){
          return false
     }
     return true
}

Menu will be shown only for 1-level items.

2) To set item context menu:

    tree.setItemContextMenu(itemId,cMenu)