"onBeforeContextMenu" not recognized

Hello all,

I’m trying to set a context menu into a grid, and to use the “onBeforeContextMenu” event. Here is my code :

var tmpMenu=new dhtmlXMenuObject(); var tmpXMLStringCat ="<menu><item id='addcat' text='Ajouter une catégorie'/> <item id='addcomp' text='Ajouter une compétence'/><item id='suppr' text='Supprimer la catégorie'/> </menu>"; tmpMenu.setIconsPath("kit/dhtmlx2.5/imgs/"); tmpMenu.renderAsContextMenu(); tmpMenu.loadXMLString(tmpXMLStringCat); tmpTreeGridCompetences.enableContextMenu(tmpMenu); tmpMenu.attachEvent("onBeforeContextMenu", function(tmpZoneId){ alert(tmpZoneId); return true; } );

But there’s no one alert box, whatever area a click in my grid. What am I doing wrong ?

Hi,

try setting onBeforeContextMenu event handler for the grid:

tmpTreeGridCompetences.attachEvent(“onBeforeContextMenu”,function(rowId,columnIndex){
alert(rowId);
return true;
});

so easy… it works !

I have another problem now… I’ve got two XMLString :

var tmpXMLStringCat ="<menu><item id='addcat' text='Ajouter une catégorie'/><item id='addcomp' text='Ajouter une compétence'/><item id='suppr' text='Supprimer la catégorie'/></menu>"; var tmpXMLStringComp="<menu><item id='desactiver' text='Desactiver la compétence'/><item id='suppr' text='Supprimer la compétence'/></menu>";

The idea is to load the first when the contextlenu is called on a “cat” row, and the second on a “comp” row. here is my code :

tmpTreeGridCompetences.attachEvent("onBeforeContextMenu", function(tmpZoneId){ var tmpReg = /^cat/; if(tmpReg.test(tmpZoneId)){ tmpMenu.loadXMLString(tmpXMLStringCat); }else{ tmpMenu.loadXMLString(tmpXMLStringComp); } return true; } );

If the regtest is correct, only the “tmpXMLStringCat” is loaded…

If there only two fixed set of items those you want to display in menu, you may load them all at once, but hide/show necessary items depending on row id.

dhtmlxGrid/samples/03_context_menu/04_pro_context_dynamic.html

dhtmlx.com/docs/products/dht … namic.html

It’s exacly what I wanted, thanks for your help.