Check documentation for the latest version of dhtmlxSuite onContextMenu DHTMLX Docs

onContextMenu

fires when the user clicks on treeview items with the right mouse button

void onContextMenu(string|number id,number x,number y,object ev);
idstring|numberthe item's id
xnumberx coordinate
ynumbery coordinate
evobjectwindow event object

Example

// init treeview
var myTreeView = new dhtmlXTreeView("parentId");
 
// enable context menu
myTreeView.enableContextMenu(true);
 
// init dhtmlx menu
var myContextMenu = new dhtmlXMenuObject({
    context: true // render it as context menu
});
 
myTreeView.attachEvent("onContextMenu", function(id, x, y, ev){
    // show context menu here
    myContextMenu.showContextMenu(x, y);
 
    // optionally, you can select treeview item
    myTreeView.selectItem(id);
 
    // prevent default context menu
    return false;
});

Back to top