Actually, you can have multiple "PanelExpanderButton"s in a Part – in fact that GoJS Buttons -- Northwoods Software page demonstrates that.
However, the current definition of “PanelExpanderButton”, given in extensions/Buttons.js, does not support nesting of those buttons in itemTemplates. Here is the new definition of “PanelExpanderButton” that will be in version 1.7. Until you upgrade to 1.7, you can use this:
go.GraphObject.defineBuilder("PanelExpanderButton", function(args) {
var eltname = /** @type {string} */ (go.GraphObject.takeBuilderArgument(args, "COLLAPSIBLE"));
var button = /** @type {Panel} */ (
go.GraphObject.make("Button",
{ // set these values for the visible binding conversion
"_buttonExpandedFigure": "TriangleUp",
"_buttonCollapsedFigure": "TriangleDown"
},
go.GraphObject.make(go.Shape, "TriangleUp",
{ name: "ButtonIcon", desiredSize: new go.Size(6, 4) },
new go.Binding("figure", "visible",
function(vis) { return vis ? button["_buttonExpandedFigure"] : button["_buttonCollapsedFigure"]; })
.ofObject(eltname)))
);
var border = button.findObject("ButtonBorder");
if (border instanceof go.Shape) {
border.stroke = null;
border.fill = "transparent";
}
button.click = function(e, button) {
var diagram = button.diagram;
if (diagram === null) return;
if (diagram.isReadOnly) return;
var elt = button.findTemplateBinder();
if (elt === null) elt = button.part;
if (elt !== null) {
var pan = elt.findObject(eltname);
if (pan !== null) {
diagram.startTransaction('Collapse/Expand Panel');
pan.visible = !pan.visible;
diagram.commitTransaction('Collapse/Expand Panel');
}
}
}
return button;
});
With this definition, you can use them inside itemTemplates for expanding or collapsing elements within the item. Here is an example:
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, { fill: "white" }),
$(go.Panel, "Table",
{ margin: 0.5 },
$(go.RowColumnDefinition, { row: 0, background: "lightgray" }),
$(go.TextBlock, { column: 0, margin: new go.Margin(2, 2, 0, 2) },
new go.Binding("text", "key")),
$("PanelExpanderButton", { column: 1, background: "lightgray", alignment: go.Spot.Right }),
$(go.Panel, "Table",
{ name: "COLLAPSIBLE", row: 1, columnSpan: 2 },
new go.Binding("itemArray", "items"),
{
itemTemplate:
$(go.Panel, "TableColumn",
$(go.Panel, "Table", { row: 0, stretch: go.GraphObject.Fill },
$(go.TextBlock, { column: 0 },
new go.Binding("text", "name")),
$("PanelExpanderButton", { column: 1 })
),
$(go.Panel, "Table", { name: "COLLAPSIBLE", row: 1, alignment: go.Spot.Top },
new go.Binding("itemArray", "details"),
{
itemTemplate:
$(go.Panel, "TableRow",
$(go.TextBlock, new go.Binding("text", ""))
)
}
)
)
}
)
)
);
myDiagram.model = new go.GraphLinksModel([
{
key: "Alpha",
items: [
{
name: "A",
details: [
"alpha",
"apple",
"active"
]
},
{
name: "B",
details: [
"beta",
"boat"
]
},
{
name: "C",
details: [
"gamma",
"cat",
"car",
"computer"
]
}
]
},
{
key: "Beta",
}
],[
{ from: "Alpha", to: "Beta" }
]);
}
This appears as:
After collapsing “C”: