How to have 2 different Group Layout Templates

I intend to use 2 or more different group templates, so that both groups can differ in shape, have ability to resize and one can not and various other properties.

If you want more than one group template, just add them to the Diagram.groupTemplateMap. Then make sure that each node data object that is represented by a Group has a category property that names the template you want to use.

Or is your question about using different Group.layouts?
You could use a data binding that returns a new layout instance that does what you want.

Diagram.groupTemplateMap works, Thanks Walter!

how can i apply dragComputation: stayInGroup for only one category of group template.

var stayInGroup = function (part, pt, gridpt) {

// don't constrain top-level nodes

var grp = part.containingGroup;

if (grp === null) return pt;

// try to stay within the background Shape of the Group

var back = grp.resizeObject;

if (back === null) return pt;

// allow dragging a Node out of a Group if the Shift key is down

if (part.diagram.lastInput.shift) return pt;

var p1 = back.getDocumentPoint(go.Spot.TopLeft);

var p2 = back.getDocumentPoint(go.Spot.BottomRight);

var b = part.actualBounds;

var loc = part.location;

// find the padding inside the group's placeholder that is around the member parts

var m = grp.placeholder.padding;

// now limit the location appropriately, assuming no grid-snapping

var x =

  Math.max(p1.x + m.left, Math.min(pt.x, p2.x - m.right - b.width - 1)) +

  (loc.x - b.x);

var y =

  Math.max(p1.y + m.top, Math.min(pt.y, p2.y - m.bottom - b.height - 1)) +

  (loc.y - b.y);

return new go.Point(x, y);

};

Just like any other property, only set { dragComputation: stayInGroup } in one of your group templates.

Or return pt;, as already shown several times in the implementation of stayInGroup when it didn’t want to constrain movement.