Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

Dynamically add custom context menu to the nodes

$
0
0

@charu.chaudhari wrote:

I am using Go JS 1.7 evaluation version for self project. I have a scenario in which I am creating diagram nodes and relationships dynamically, that is, by fetching values from database. I want to show context menu on the node displayed in the diagram as per its Name property. I looked into some samples :

But these samples creates all the HTML menu in the HTML page and then just use show or hide functionality to displaay menu accordingly. In my case there could me 8-10 context menu on one node and hence creating all the menus before hand is not a option for me. Is there a way I can dynamically add context menu to the diagram?
I have tried a simple code:

var cxTool = $scope.myDiagram.toolManager.contextMenuTool;

 cxTool.showContextMenu = function(contextmenu, obj) {
                if(obj.part.data.properties.Name === 'Something'){
                    $scope.myDiagram.contextMenu =
                        $(go.Adornment, "Vertical",
                            $("ContextMenuButton",
                                $(go.TextBlock, "Change Color for Something"),
                                { click: changeColor }
                            )
                        );
                } else if(obj.part.data.properties.Name === 'SomethingElse'){
                    $scope.myDiagram.contextMenu =
                        $(go.Adornment, "Vertical",
                            $("ContextMenuButton",
                                $(go.TextBlock, "Change Color for SomethingElse"),
                                { click: changeColor }
                            )
                        );
                }
}

But thus code does not create context menu. Can you please provide some solution for it?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles