Grid Context menu hideItem not working

Hi there,
I am configuring the context menu on my grid using an xml file.
I then need to hide and show menu items based on the column index. I do this by calling the function below on the “onBeforeContextMenu” event of the grid. The function executes as expected, it even changes the isHidden status of the menu items correctly. The problem however is that the menu that is shown after exiting this function is the original menu loaded via XML and does not reflect the updates made by the “onShowMenu” function below.

dhxGrid.attachEvent("onBeforeContextMenu", onShowMenu);

function onShowMenu(rowId, celInd, grid) {
  /* hide show items based on context */
  var arr = ["info", "olap", "drill_up_to", "drill_down", "drill_into", "drill_up", "chart","top10", "bottom10","donut", "gauge"];
    for (var i = 0; i < arr.length; i++) {
        cmenuGrid.hideItem(arr[i]);
    }
  var dateIdx = dhxGrid.getColIndexById("DATETIME");
    switch (true) {
    case (celInd < dateIdx-1):
        cmenuGrid.showItem("olap");
        cmenuGrid.showItem("drill_up_to");
        break;
    case (celInd == dateIdx-1):
        cmenuGrid.showItem("olap");
        cmenuGrid.showItem("drill_down");
        break;
    case (celInd == dateIdx):
        cmenuGrid.showItem("olap");        
        cmenuGrid.showItem("drill_up");
        cmenuGrid.showItem("drill_down");
        break;
    case (celInd > dateIdx):
        cmenuGrid.showItem("info");  
        cmenuGrid.showItem("olap");        
        cmenuGrid.showItem("drill_into");
        cmenuGrid.showItem("chart");
        cmenuGrid.showItem("top10");
        cmenuGrid.showItem("bottom10");
        cmenuGrid.showItem("donut");
        cmenuGrid.showItem("gauge");
        cmenuGrid.showItem("trend");
        break;    
    }
    return true;

}

I have been stuck on this for several hours. Please help if you can!

Many thanks,
Rose

Hi,

The problem however is that the menu that is shown after exiting this function is the original menu loaded

Why the menu is loaded after it is opened ? Please have a look at the working sample:

dhtmlxGrid/samples/03_context_menu/04_pro_context_dynamic.html

Hi Alexandra,
thank you for getting back to me.
I am not loading the menu after it is opened. I load the menu once only, before it is ever opened. I execute the function below after the grid is loaded.

[code]

function initContextMenuforGrid() {
cmenuGrid = new dhtmlXMenuObject();
cmenuGrid.setIconsPath("/i/libraries/optima/imgs/");
cmenuGrid.renderAsContextMenu();
cmenuGrid.setSkin(“dhx_skyblue”);
cmenuGrid.loadXML("/i/libraries/optima/common/dyn_menu.xml");

cmenuGrid.attachEvent(“onclick”,function(id, zoneId, casState){
onGridClick(id,zoneId); });

}[/code]
Then every time before the context menu is displayed I call the function in my previous post to hide and show particular items, but this has no effect on the menu that gets displayed, even though the function runs and appears to be updating the isHidden status of the items correctly.

I already originally used the sample as guidance, but am still stuck unfortunately.

Is there anywhere else I could be going wrong?

thank you,
Rose

Alexandra, thank you so very much. I see what you meant with “Why am Ioading it after it is shown”. With “it” you meant the grid, while I interpreted is as the menu.
It’s working perfectly now that I am loading the menu XML BEFORE enabling the context menu on the grid.
thank you again.

Hi Rose,

I’m glad to know that you have solved the problem.