Group - UnGroup Behavior in Diagram

How one can implement group & ungroup functionality and preserve same.
Also, when nodes are grouped, while moving it should move all nodes which are grouped.

Can you provide a sample for same.?

You just need to enable the groupSelection and ungroupSelection commands, as for example in Basic GoJS Sample.