Here is my group layout code.
myDiagram.groupTemplate =
$(go.Group, “Auto”,
new go.Binding("layout", "lyt"),
$(go.Panel, "Auto",
$(go.Shape, "Rectangle", // surrounds the Placeholder
{
fill: "rgba(128,128,128,0.33)"
},
new go.Binding("desiredSize", "size", go.Size.parse),
),
$(go.Placeholder,
{alignment: go.Spot.Center}) // with some extra padding around them
),
{contextMenu:nodeMenu},
{
contextMenu:
$(go.Adornment, "Vertical",
new go.Binding("itemArray", "commands"),
{
itemTemplate:
$("ContextMenuButton",
$(go.TextBlock, new go.Binding("text")),
{
click: function(e, button) {
var cmd = button.data;
var nodedata = button.part.adornedPart.data;
console.log("On " + cmd.text + ": " + cmd.action);
}
}
)
}
)
}
);
here is my nodearray
“nodeDataArray”: [
{
“key”: “main”,
“name”: “MainShelf”,
“size”: “600 600”,
“lyt”:$(go.GridLayout, { alignment: go.GridLayout.Position }),
“isGroup”: true
},
{
“key”: “slot1”,
“name”: “Slot1”,
“lyt”:$(go.GridLayout, { wrappingColumn: 1, alignment: go.GridLayout.Position}),
“size”: “120 250”,
“cellwidth”:150,
“cellheight”:450,
“color”:“lightgrey”,
“isGroup”: true,
“group”: “main”,
“commands”: [
{ “text”: “Add Card”, “action”: “addCard”},
{ “text”: “Add Slot”, “action”: “add Slot”}
]
},
{
“key”: “slot2”,
“name”: “Slot2”,
“size”: “120 250”,
“lyt”:$(go.GridLayout, { wrappingColumn: 1, alignment: go.GridLayout.Position}),
“color”:“lightgrey”,
“cellwidth”:200,
“cellheight”:450,
“isGroup”: true,
“group”: “main”,
“commands”: [
{ “text”: “Add Card”, “action”: “addCard” },
{ “text”: “Add Port”, “action”: “addPort” }
]
},
{
“key”: “card2”,
“size”: “100 100”,
“color”: “lightgrey”,
“group”: “slot1”,
“lyt”:$(go.GridLayout, { wrappingColumn: 1 }),
“name”:“Card2”,
“isGroup”:true,
“commands”: [
{ “text”: “Add Port”, “action”: “addPort” },
{ “text”: “Add Link”, “action”: “addLink” }
]
},
{
“key”: “card3”,
“size”: “100 100”,
“color”: “lightgrey”,
“group”: “slot1”,
“lyt”:$(go.GridLayout, { wrappingColumn: 1 }),
“name”:“Card3”,
“isGroup”:true,
“commands”: [
{ “text”: “Add Port”, “action”: “addPort” },
{ “text”: “Add Link”, “action”: “addLink” }
]
},
{
“key”: “innerslot”,
“name”: “InnerSlot1”,
“size”: “30 30”,
“isGroup”: true,
“group”: “card3”
},
{
“key”: “innerslot2”,
“name”: “InnerSlot3”,
“size”: “30 30”,
“isGroup”: true,
“group”: “card3”
},
I am passing complete layout from node array to make it dynamic.