right click to both select task and bring up context menu

Hi,

I tried to change the selected task to the task that I right clicked on (it will highlight the right clicked task instead of the task you clicked on before). So I tried to add gantt.selectTask in the onContextMenu event. When I debug it step by step it seems to work until the point to return false, but then it jumped to somewhere else, and the context menu would not show, only the task that I right clicked on will be selected. Is there anyway to do it?

Thanks

Hi,
looks like selecting a task from onContextMenu handler prevents the menu from showing for some reason. The simplest fix would be to call gantt.selectTask from a timeout, e.g.

[code]gantt.attachEvent(“onContextMenu”, function(taskId, linkId, event){
var x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;

if(taskId){
	// select task
	setTimeout(function(){
		gantt.selectTask(taskId);
	},1);

	//show context menu
	menu.showContextMenu(x, y);
}

if(taskId){
	return false;
}

return true;

});[/code]

Thanks for the reply, this worked.

Hi! This solution worked for me:

gantt.attachEvent('onContextMenu', function (id, linkId, e) {
     id ? setMenuAnchor(e.target) : setMenuAnchor(null)
      if (id) {
        gantt.silent(() => gantt.selectTask(id))
      }
    })