Remove node from group via context menu button

I suspect this is easy, but I’m new to the platform and I’ve already wasted a couple hours on topics very tangential to this experimenting, looking through samples, and the forum.

I’m customizing the basic example to make moving nodes into & out of groups easier. I have successfully implemented a “Add Node in Group” function with the following code:

makeButton("Add Node in Group",
      function(e, obj) {  // OBJ is this Button
          var contextmenu = obj.part;  // the Button is in the context menu Adornment
          var part = contextmenu.adornedPart;  
          myDiagram.startTransaction('context menu click');
          myDiagram.model.addNodeData({"text":"default text","group":part.key});
          myDiagram.commitTransaction('context menu click');
        }),

My difficulty has been trying to do the reverse.

makeButton("Remove Node from Group",
      function(e, obj) {  // OBJ is this Button
          var contextmenu = obj.part;  // the Button is in the context menu Adornment
          var part = contextmenu.adornedPart;  
          myDiagram.startTransaction('context menu click');
          //some code to remove the "group" data from this node
          myDiagram.commitTransaction('context menu click');
        }),

I’ve not yet run into how to simply remove a data property.

Help is appreciated. Noob question, hopefully an easy answer.

There are several ways of doing it.

If you want to just modify the member node data object, you can do:

myDiagram.model.setDataProperty(part.data, "group", undefined);

or more generally:

myDiagram.model.setGroupKeyForData(part.data, undefined);

But you could also just manipulate the Part in the Diagram directly, as you could not do when creating a new Node:

part.containingGroup = null;

All of the above statements naturally should take place in the transaction that you have already correctly set up.

This is excellent help. Exactly what I needed and more, even more useful than just a simple “here’s your fish”.

Genuine thanks for the robust & accurate answer so quickly.