Could you please point me in the right direction …
I have a data view with context menu attached to it. If I select an item in the data view I can obtain its id from a context menu onClick event handler using getSelected() method. However, I can’t figure out how to obtain an id of the data view item without having to select one. Basically what I am looking for is an equivalent of the contextID property available in the dhtmlxTree component.
What approach are you using to set context menu for Dataview? The correct approach is using onBeforeContextMenu event:
dataview.attachEvent(“onBeforeContextMenu”,function(itemId,e){
/method that shows context menu/
return false;
});
This event takes dataview item id and native event object that will help to position menu. If you are using dhtmlxMenu as context menu, you may use showContextMenu(x,y) method to show the menu in a certain position.
I think I am using the correct approach you’ve mentioned. What I am trying to do is to avoid using global variable to retrieve data view itemId from the context menu as in the following code:
// setup context menu
var dataViewCtxMenu = new dhtmlXMenuObject();
dataViewCtxMenu.setIconsPath(’@{views.dhtmlx.DhtmlxParameter.DhxLibImgsUrl}’);
dataViewCtxMenu.renderAsContextMenu();
dataViewCtxMenu.attachEvent(“onClick”, onDataViewCtxMenuButtonClick);
dataViewCtxMenu.loadXML(‘dataViewCtxMenuXml’);
// define global variable to be used from context menu onClick event handler
var myGlobalVar = ‘not set’;
dataView.attachEvent(“onBeforeContextMenu”, function(itemId, e) {
var x = e.clientX;
var y = e.clientY;
myGlobalVar = itemId;
dataViewCtxMenu.showContextMenu(x, y);
return false;
})
function onDataViewCtxMenuButtonClick(menuItemId, type) {
alert(“myGlobalVar=” + myGlobalVar);
}
Dataview doesn’t provide a ready implementation with dhtmlxMenu. Therefore, there is not contextID property like in dhtmlxTree. However, you may try to set it )
dataView.attachEvent(“onBeforeContextMenu”, function(itemId, e) {
var x = e.clientX;
var y = e.clientY;
this.contextID = itemId;
dataViewCtxMenu.showContextMenu(x, y);
return false;
})
function onDataViewCtxMenuButtonClick(menuItemId, type) {
alert(dataView.contextID);
}