Adding group to model object

Hi,

I am grouping objects using groupSelection(). But this grouping was not reflected in the diagram model object. so i tried the using the below in the contextmenu button click event.
var linkDataArray = [{ key: “Omega”, isGroup: true }];

                   var iteration = e.diagram.selection.iterator;
                   
                   wiDiagram.startTransaction('modified group');
                   while (iteration.next()) {
                       wiDiagram.model.setDataProperty(iteration.value, "group", "Omega");
                   }
                   wiDiagram.commitTransaction('modified group');
                   wiDiagram.model = new go.GraphLinksModel(linkDataArray);

The above code doesnt create group. Kindly guide me

Are you using the debug library and checking console output for warning and error messages? You should have seen the warning about Model.setDataProperty being passed a GraphObject or Part. Diagram | GoJS API is a collection of Parts. You want to set the property on the .data.

ya, it gets grouped now. But i have a panel inside groupTemplate which i am unable to set it to model object.

Only Parts and Panels representing items in Panel.itemArrays will have Panel.data bound to data. All the rest of the Panels in a Part must not have their own data – they are bound to their containing Part’s data or their containing item Panel’s data.

So some Panel inside a Group should not be bound to its own data. And I am unclear what your question really is.

Actually i have a groupTemplate which contains panel inside the group. When i converted the diagram to json, i didnt get the group info, so i first asked about adding group info to model. Now i am getting the group info but even after the panel binding , the panel info is missing in the json model.

var iteration = group.elements.iterator;


while (iteration.next()) {
    if (iteration.value instanceof go.Panel) {
        floorplan.startTransaction("panel selection");
        floorplan.model.setDataProperty(iteration.value, "loc", tmp.position.x + " " + tmp.position.y);
        floorplan.commitTransaction("panel selection");
    }

Please reread GoJS Using Models -- Northwoods Software and GoJS Data Binding -- Northwoods Software. and if you have item arrays, GoJS Item Arrays-- Northwoods Software.

Basically, GoJS uses a model-view architecture. The model data is related to the bound Parts’ GraphObjects copied from templates via data Bindings. This allows the data in the model to be vastly simpler than the visual elements in the diagram. And one can simultaneously have multiple representations in different diagrams of the same model data, by using different templates.

GoJS does not use a document architecture, where there is a one-to-one mapping between the objects that are stored in a file/database and the visual objects seen in the diagram. In document architectures every element is written out with with every non-default property value. Using templates and data binding allows one to greatly simplify the saved data, avoiding immense quantities of duplicated data when there is more than one copy of a node or a link.

So my answer is to use data binding. Probably TwoWay Bindings for those properties whose values change via your code.