Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by PA on Oct 12, 2008 09:49
open dhtmlx forum
dhtmlXTree and contextMenu

Hi,
I have a requirement: Do not show 2 options on the context menu if the tree item selected is the root (the first node in the tree).How can this be achieved?

I have tried many approaches but it does not work. One such approach is shown below:

tree.attachEvent("onClick",function(){
    if (tree.getSelectedItemId() != "HO") {
        cMenu.menu.hideItem("deleteRU");
        cMenu.menu.hideItem("renameRU");
    }
    return true;
    });
tree.attachEvent("onRightClick",function(){
    if (tree.getSelectedItemId() != "HO") {
        cMenu.menu.hideItem("deleteRU");
        cMenu.menu.hideItem("renameRU");
    }
    return true;
});

Please suggest if there is a way to achieve this requirement
Answer posted by Support on Oct 13, 2008 02:07
The code which you are using is correct, but you must not use getSelectedItemId - in moment of right click event , item in question is not selected yet. Instead of it you can use parameter of event.

tree.attachEvent("onRightClick",function(id){ 
  cMenu.menu.showItems(); //to restore previously hidden items
  if (id!= "HO") { 
  cMenu.menu.hideItem("deleteRU"); 
  cMenu.menu.hideItem("renameRU"); 
  } 
  return true; 
});