Reference Node Data in Custom Context Menu

Hey there I'm planning to implement a custom context menu to my Node Diagram, the problem that I'm facing is that I cannot get functions to work that reference node data. It's best explained in an example I guess, so just simply lets say I want to add a search function to the HTML Context Menu from the example: I've tried 2 methods (Search and Search2)

[code]function cxcommand(val) { var diagram = myDiagram; if (!(diagram.currentTool instanceof go.ContextMenuTool)) return; switch (val) { case "Cut": diagram.commandHandler.cutSelection(); break; case "Copy": diagram.commandHandler.copySelection(); break; case "Paste": diagram.commandHandler.pasteSelection(diagram.lastInput.documentPoint); break; case "Delete": diagram.commandHandler.deleteSelection(); break; case "Color": changeColor(diagram); break;

case "Search": searchMe(event, node); break;

case "Search2": window.location.href = "#" +; break;

} diagram.currentTool.stopTool(); }

function searchMe(event, node) {window.location.href = "#" +; }


For both I need to reference node data in the function but it won't let me. I feel like I didn't understand something here and I also feel very confused since I tried out alot of stuff now. I hope you can help me with that!

Big thanks


Given your Diagram:

    diagram.findPartAt(diagram.toolManager.contextMenuTool.mouseDownPoint, false)

will return the Node for which the context menu was invoked.

For version 1.4 we will make public the ContextMenuTool.currentObject property, which remembers the value that is passed to showContextMenu and positionContextMenu as the second argument. You could implement this yourself in your override of showContextMenu, where you could remember the second argument so that your menu commands could access it.

So in the future, you would be able to use:


to refer to the object (a Node in this case) that has the context menu.

Thanks for the tip with the diagram.findPart function, I managed to work around it with the following:

[code] function searchMe(diagram) { diagram.selection.each(function(node) { if (node instanceof go.Node) { window.location.href = "#" +; } }); } [/code]

With version 1.4 it will definately become easyer, any information on when 1.4 will arrive?

It doesn’t make sense to replace the window.location for each of the Nodes in your Diagram. Only the last one will take effect.

Maybe a week, assuming there aren’t any serious bugs reported.

Thats good news, thanks! And it works for me since I have a secondary DIV with seperate scrollbars which includes chapters with ID’s similar to the node keys. So ref #“” is a shortcut to the corresponding chapter.

A post was merged into an existing topic: Reimplementing GoJS context menu in HTML