hideItem() in dhtmlXMenuObject not hiding the items

Hi there,
I am configuring the context menu on my grid using an xml file.
I then need to hide and show specific menu items based on the business logic. I do this by calling the function below on the “onBeforeContextMenu”
event of the grid. I followed the following logic as per your reference example :-

  1. Hide all the menu items using hideItem()
  2. Make specific items visible using showItem() on basis of business logic.

The issue that I am facing is that all the 3 items in menu appear on grid after exiting changeMenu() function.
Uncommenting alert statement in changeMenu() outputs as null. I am using IE6 and unfortunately I need to stick to it.

Please help.

Thanks,
Kamlesh

XML file format

JSP Code

//Menu intialization
var menu=new dhtmlXMenuObject();
menu.renderAsContextMenu();
menu.attachEvent("onClick", onMenuClick);
menu.loadXML("/fams/dhtmlx/context.xml");

//Tree Grid intialization
mygrid = new dhtmlXGridObject('gridbox');
//additional code related to mygrid
mygrid.enableContextMenu(menu);
mygrid.init();
mygrid.attachEvent("onBeforeContextMenu", changeMenu);       
mygrid.enableDragAndDrop(false);
mygrid.enableLightMouseNavigation(true);


// At later point in code - on basis of users seletion on UI, following method is called to populate
// data in the Grid

function loadExpenseData(url){
	mygrid.editStop(true);
	mygrid.clearAll();
	mygrid.loadXML(url,doAfterRefresh);
	document.getElementById("gridbox").style.cursor = 'wait';
	popupMessageBox("Loading...");
	showStatus('Loading...');
	mygrid.editStop(false);
	
}

function changeMenu(rowId, celInd, grid){
var str = mygrid.getUserData(rowId,“level”);
var arr = [“add”, “cpfw”,“paste”]; //cpfw - copy forward
for (var i = 0; i < arr.length; i++) {
menu.hideItem(arr[i]);
//alert(“isItemHidden “+menu.isItemHidden(arr[i]) );
}
var readOnly = mygrid.getUserData(””,“readonly”);
if( readOnly!=null && readOnly == “0”){
if(str!=null){
var level = str.split(’,’)[0];
if(level==‘R’) menu.showItem(“add”);
if(celInd >= getActualsMonth() && level==‘E’) menu.showItem(“cpfw”);
if(window.clipboardData.getData(“Text”)!=null && window.clipboardData.getData(“Text”).trim() !=""){
if(celInd >= getActualsMonth() && level==‘E’) menu.showItem(“paste”);
}
}
}else
return false;

    return true;
}

Try to use similar function:

mygrid.attachEvent("onBeforeContextMenu", function(id) { var UD = mygrid.getUserData(id,"hide") if (UD == "hide") { menu.hideItem('cpfw'); } else { menu.showItem('cpfw'); } return true; });

In grid my userdata is look like

<userdata name="hide">hide</userdata>

In menu i used your XML


To decide your issue you need to share your grid-xml-structure with userdata tags…

I tried your suggestion regarding mygrid.attachEvent . But the result was same. Even after hiding the menu item, it still appeared after existing the function. Not able to attach xml file . Trying to paste below :-

<?xml version="1.0" encoding="UTF-8"?>

O,14852Head1R,210002Head2E,36007Head3115.00068.55068.550118.450118.450118.448118.452118.450118.450118.450118.450118.450R,210002Head4S,36030Head59.5114.7794.7278.4638.2508.1898.9398.3028.1298.3288.3208.307S,36030Head65.6512.2201.0101.2384.359.915.471.964.884.508.508.508S,36030Head816.4949.4698.53815.69115.62115.08714.88215.23215.23415.29915.29915.299R,210002Head9S,36051Head10.105.105.105.105.105.105.108.105.105.105.105.105R,210002Head12000000000000R,210002Head13E,36093Head141.0181.0181.0181.0181.0181.0181.0181.0181.0181.0181.0181.018S,36093Head151.0181.0181.0181.0181.0181.0181.0181.0181.0181.0181.0181.018R,210002Head16E,36078Head176.4636.4626.4626.4636.4626.4626.4636.4636.4636.4636.4636.463E,36078Head181.4381.4381.4381.4381.4381.4381.4381.4381.4381.4381.4381.438R,210002Legal000000000000R,210002Head19R,36147Head20000000000000R,210002Head21000000000000R,210002Head22E,36169Head231.0001.0001.0001.0001.0001.0001.0001.0001.0001.0001.0001.000R,210002Head24000000000000R,210002Head25000000000000R,210002Head26000000000000R,210002Head27R,36237Head28000000000000R,36237Head29000000000000R,210002Head30000000000000O,210002Head31R,36240Head32000000000000R,36240Head33E,416934Head341.2321.2321.2321.2321.2321.2321.2321.2321.2321.2321.2321.232E,416934Head350.273.137.137.137.137.137.137.137.137.137.137E,416934Head361.4951.5221.5151.5171.5151.5151.5161.5161.5161.5161.5161.516R,36240Head37E,416952Head38.180.171.172.171.171.177.171.171.172.171.171.177E,416952Head393.0573.0553.0533.1733.0533.0533.0563.0553.0553.0573.0573.057E,416952Head401.3321.2681.2671.2661.2711.2711.2631.2641.2641.2661.2641.264E,416952Head41.215.215.215.215.215.215.215.215.215.215.215.215E,416952Head422.7112.7112.7112.7112.7112.7112.7112.7112.7112.7112.7112.711R,36240Head43E,416910Head44.942.942.942.918.864.804.756.702.642.588.534.486E,416910Head452.0151.9561.9551.9591.9471.9461.9491.9481.9481.9481.9481.948E,416910Head46-172.876-173.291-169.357-170.182-172.836-168.745-168.792-168.941-168.629-168.467-168.403-168.348R,210002Head47R,36238Head48000000000000R,36238Head49000000000000R,36238Head50000000000000E,36238Head511.4381.4381.4381.4381.4381.4381.4381.4381.4381.4381.4381.438R,210002Head52O,36262Head53R,46246Head54000000000000R,46246Head55000000000000O,36262Head56R,46261Head57000000000000R,46261Head58000000000000O,14852Head59R,24824Head60E,36265Head61115.000110.000110.000115.000115.000114.998115.002115.000115.000115.000115.000115.000R,24824Head62000000000000E,Head63000000000000E,Head640000000000000

Whether methods hideItem() & showItem() are working in general?
They are working in my sample.
I advise you to make a demo and ask your question in the support system.