To watch when the order of a node within a group is altered

Hi, I am looking at the example posted here (Regrouping Demo) and I would like to know if there is any possibility to watch when the order of a node within a group is altered, for example : in the diagram “Group A” has “firstA” and “SecondA”, I need watch the change their order and then to use the Save button to generate the new JSON with the result, is it possible to do that? If possible, how is it done?.

The layout is performed by each Group.layout and the Diagram.layout for the top-level nodes. So I suppose you could either override the Layout.commitLayout method or implement a “LayoutCompleted” DiagramEvent listener.

But if you see what some of the samples do, they implement a ModelChanged listener on the diagram, check whether ChangedEvent.isTransactionFinished is true, and then save the model. Please read GoJS Changed Events -- Northwoods Software

thanks for your answer. I tried to implement this event and print the result using e.model.toJson (), but the change made to the diagram for two nodes into the same group is not detected.

Ah, that is probably because there is no TwoWay Binding on the Node.location property for both the node template and the group template, so that the positional information is saved in the model data. You can add this:

    new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify)

to your templates, and then you will see the node locations saved in the model data.

The basic idea is that a layout will position nodes (and route links) but has no knowledge of any model data, which is very app-specific. Instead of depending on getting the data from the x locations of the nodes, perhaps you really just want to sort each Group’s member nodes by their location and just remember that ordering.