How to create right-click menu after selecting mutiple nodes?

Is it possible to create contextmenu or right-click menu after selecting multiple nodes or links?
if possible, how to do it?
I would like to trigger some events after selecting some nodes/links in my diagram.


Yes, just define a context menu the normal way, as described at GoJS Context Menus -- Northwoods Software.

You can make some or all of the commands be enabled or visible only when the conditions are correct for those commands, which may include the exact number and types of selected Parts. That is also demonstrated on that Introduction page about Context Menus, and can be seen in several of the samples if you search for “ContextMenuButton”.

Maybe something like:

    . . .,
    new go.Binding("visible", "", function(o) { return o.diagram.selection.count === 2; }).ofObject(),
    . . .,

if you want that particular command to be visible only if the number of selected Parts in the diagram is exactly 2.

Thanks Walter for your quick reply.
as you said in example GoJS Context Menus -- Northwoods Software, if I select both nodes and want to change both node’s color at the same time, how can I do it? how to get the objects from the selection?


myDiagram.selection contains all Parts in the selection. So you could loop through them:

myDiagram.selection.each(function(part) {
  // do something to each part here

If you have a Binding on some brush property (maybe Shape.fill or Shape.stroke) and the source is some property on your node data (let’s say “color”), you could do:

myDiagram.commit(function(diag) {
    diag.selection.each(function(part) {
        if (part instanceof go.Node) {
            diag.model.set(, "color", "blue");
}, "changed colors");