Search code examples
javascriptcontextmenutoolbardhtmlx

How to attach a context menu to a button


I'm trying to attach a context menu to a button on my toolbar.

Here is my code:

contex_order = new dhtmlXMenuObject();
contex_order.renderAsContextMenu();
contex_order.loadStruct(cont_m);
...
            toolbarOrder = new dhtmlXToolbarObject("tab_ord");
            toolbarOrder.setIconsPath("dhtmlx/codebase/imgs/");
            toolbarOrder.attachEvent("onClick", function(id){
if (id=="save")
    contex_order.showContextMenu(100,50)
            });

But clicking on that button doesn't make the context menu show up. There is no error in the browser console, just nothing.

Did anyone have such kind of a problem? How can I make the menu be shown?


Solution

  • Please, try to call the showContextMenu() method with the timeout:

    setTimeout(function() {
      contex_order.showContextMenu(100,50)
    }, 50)
    

    as the menu shows up at the same time with the button click this button click closes the menu at the same time.