Articles in this section
Category / Section

How to restrict the child node dragging whereas allow group dragging

4 mins read


Creating and managing group nodes in a diagram is a powerful feature that enables you to organize and manipulate related nodes collectively. In this tutorial, we'll explore how to create a group node, drag it, and restrict the dragging behavior of its child nodes individually.

To create a group node, leverage the children property of the node. Here's a code sample illustrating the creation of a group node along with its child nodes:

var nodes = [

        {

            id: "node1",

            width: 50,

            height: 50,

            offsetX: 100,

            offsetY: 100,

            annotations: [{ content: "Seat1" }]

          },

          {

            id: "node2",

            width: 50,

            height: 50,

            offsetX: 200,

            offsetY: 100,

            annotations: [{ content: "Seat2" }]

          },

          {

            id: "node3",

            width: 50,

            height: 50,

            offsetX: 100,

            offsetY: 200,

            annotations: [{ content: "Seat3" }]

          },

          {

            id: "node4",

            width: 50,

            height: 50,

            offsetX: 200,

            offsetY: 200,

            annotations: [{ content: "Seat4" }]

          },

          {

            id: "group", children: ['node1', 'node2', 'node3', 'node4']

          },

    ];


In this example, you can drag both the parent (group) node and its child nodes. However, there might be scenarios where you want to restrict dragging for child nodes individually. This can be achieved using the SelectionChange event and modifying the constraints of the child nodes accordingly.

Here's a code snippet demonstrating how to change the constraints of child nodes in the SelectionChange event:

//To disable drag constraints for child nodes in group node

function selectionChange(args) {

    let node;

    if ((args.newValue[0]) && (args.newValue[0]).children !== undefined) {

        const group = args.newValue[0];

        if (group.children) {

            group.constraints = ej.diagrams.NodeConstraints.Default

            for (var i = 0; i < group.children.length; i++) {

                node = diagram.getObject(group.children[i]);

                if (node.constraints) {

                    node.constraints = ej.diagrams.NodeConstraints.Default;

                }

            }

        }

    } else if (!(args.newValue[0].children)) {

        (args.newValue[0]).constraints = ej.diagrams.NodeConstraints.Select | ej.diagrams.NodeConstraints.Drag;

    }

}

By utilizing the SelectionChange event, you can dynamically adjust the constraints of child nodes when the group node is selected, providing a flexible and interactive diagramming experience.


Sample



Conclusion

I hope you enjoyed learning about how to restrict the child node dragging whereas allow group dragging.

You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.  You can also explore our JavaScript Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!







Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied