Setting group property in archetypeNodeData

I am dynamically building and setting archetypeNodeData with a number of properties. When I read back archetypeNodeData it has group attached but when I double click in the diagram it creates a node with all the properties attached and set except the group one. if I change the name to grp it works fine. If I set the property as a property called group in the nodeDataArray nodes it recalls and uses it appropriately.

What is it about the property group which prevents it from being added in this way?

Thanks

When using a GraphLinksModel, the “group” property on the data is used to refer to the Group that contains that Node.

But you can change the property name that it uses to be something else. Just set:
https://gojs.net/latest/api/symbols/GraphLinksModel.html#nodeGroupKeyProperty
to be something else, and you can go back to use “group” to mean whatever you were intending it to mean for your app.

If you intend to use Groups in your app, you’ll want to use that property to indicate membership in a group. If you do not intend to use Groups in your app, you won’t be using that property, so it doesn’t matter. Or just set it to the empty string, so that no node can be a member of a group.

$(go.GraphLinksModel, {
  nodeGroupKeyProperty: "grp",
  nodeDataArray: . . .,
  linkDataArray: . . .
})

Thanks Walter.

I am using the group property to define the group I want the node to be in when added to the diagram, i.e I am using it as intended. I am just trying to set it programatically in the achetypeNodeData ahead of it being added to the diagram via a double click.

Thoughts?

Sorry, I completely misunderstood your situation and what you are trying to do.

The ClickCreatingTool.archetypeNodeData object is copied and the copy is added to the model. But copying an individual node data object or link data object will not copy any unresolved relationships – so no nodedata.group property value nor any linkdata.from or linkdata.to property value. The copying code is responsible for resolving any relationships. There are many reasonable policies that can be implemented regarding relationships with parts. For example, in your case, the reference to the group could be resolved in the target model, as I think you are expecting. But it could instead be resolved to nothing, as actually happens, leaving it as a top-level part. Or it could be resolved to some existing group, or one that is newly created for it. And even relationships between parts in a copied collection can be modified too – for example there might be only one instance of a particular object allowed in a model. Various apps can have different requirements than what you might expect.

Anyway, the normal way to implement what you want is in a “PartCreated” DiagramEvent listener. Just add the e.subject to be a member of the Group that you want.

      $(go.Diagram, "myDiagramDiv",
        {
          "clickCreatingTool.archetypeNodeData": { text: "M", color: "yellow" },
          "PartCreated": function(e) {
            e.subject.containingGroup = e.diagram.findNodeForKey(5)
          },

Thanks Walter, that worked well, it performs as expected now.