Context on an empty tree/grid

I’m trying to get my context menu to work when the tree/grid is empty. I’ve tried to copy some of the responses to similar knowledgebase questions but have been unsuccessful. Hope you can point me in the right direction. Thanks.



vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    context_menu = new dhtmlXMenuObject(null, “standard”);

    context_menu.setImagePath(“js/dhtmlxMenu/imgs/”);

    context_menu.setIconsPath(“js/dhtmlxMenu/imgs/”);

    context_menu.renderAsContextMenu();

    context_menu.setOpenMode(“web”);

    context_menu.setWebModeTimeout(300);

    context_menu.loadXML(“projects_context_menu.xml”);

    

    …

    

    project_grid = new dhtmlXGridObject(‘project_div’);

    …

    project_grid.enableContextMenu(context_menu);

    …

    project_grid.init();

    project_grid.loadXML(“load_projects.php”);



    …

    

    



^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



The next command
project_grid.enableContextMenu(context_menu);
enables context menu support for rows in grid.
If you need to have it for empty space as well, you can add one more row
context_menu.addContextZone(‘project_div’); //for dhtmlxmenu 2.x

I’m afraid I’m still unable to get it to work. 

I have both the following lines together in my code:
project_grid.enableContextMenu(context_menu);
context_menu.addContextZone(‘project_div’); 

They appear after the
context_menu.loadXML(“projects_context_menu.xml”);
but before the
project_grid.init(); and
project_grid.loadXML(“load_projects.php”);

I have dhtmlxmenu v.2.0 build 81009


Please try to use next code, which is more stable solution

project_grid.init();
project_grid.objBox.id=project_grid.uid();
context_menu.addContextZone(project_grid.objBox.id);

Working sample sent by email


Thanks. That worked, however, it appears that the addContextZone might be conflicting with (or preventing the triggering of) the ‘onBeforeContextMenu’ event:



 context_menu.attachEvent(“onBeforeContextMenu”, …




Is there a workaround?  I’m using the ‘onBeforeContextMenu’ event to show/hide menu items, depending on the object the right-clicked is triggered from.



Thanks

onBeforeContextMenu generated only for cases when menu initialized by grid. In above case , the context menu use independent context call handler , so no event generated.
You can try to use event of menu - "onContextMenu"

context_menu.attach_event(“onContextMenu”,function(id){
//called nearly the same as onBeforeContextMenu event of grid, but will work for independent context zones as well
})