Hi,
So I recently discovered the usage of context menu on grids, and I’ve been using it a lot. Unfortunately, I came upon a problem when the grid is empty : the menu never shows up. It’s really a problem when in this very menu there is an option to add a row…
Did I do something wrong ? Can, I attach the menu on the grid entbox for instance?
sematik
January 29, 2014, 3:09pm
#3
Please, try to add the following code after the init of the grid:
mygrid.init()
mygrid.entBox.id = "gridBody";
menu.addContextZone("gridBody");
Hi,
Thanks, it works.
I added a feature to disable some menu options depending on where I clicked. Here is the code :
//Grid
var tmpGrid = new dhtmlXGridObject();
//[...]
tmpGrid.init();
tmpGrid .entBox.id = "gridBody";
tmpGrid.attachEvent("onRightClick",
function(pRow){
this.selectRowById(pRow);
tmpMenu.setItemEnabled("opt2");
return true;
}
);
//Menu
var tmpMenu = new dhtmlXMenuObject();
tmpMenu.renderAsContextMenu();
tmpMenu.addNewChild(tmpMenu.topId,0,"opt1","Option 1");
tmpMenu.addNewSibling("opt1","opt2","Option 2");
tmpMenu.addNewSibling("opt2","opt3","Option 3");
tmpGrid.enableContextMenu(tmpMenu);
tmpMenu.addContextZone("gridBody");
tmpMenu.attachEvent("onClick",
function(pIdMenu){
console.log("[MENU] (clic) "+pIdMenu);
}
);
tmpMenu.attachEvent("onBeforeContextMenu",
function(pZone){
console.log("[MENU] (zone before) "+pZone);
this.setItemDisabled("opt2");
return true;
}
);
(sorry, I can’t find the “edit post” function)
Just a precision :
a menu.attachEvent(onBeforeContextMenu) will only be called on a right-click on the grid entbox (or whatever my context zone id)
a grid.attachEvent("onBeforeContextMenu) will be called wherever I click in my grid (row or not), but without any distinction in the zoneId.
Regards,