10
Views
1
Comments
[GTree] How to add a new node
Forge component by Pedro Neto
6
Published on 18 May 2020
Application Type
Reactive

How to add a new node as parent or inside a parent node? 

And also .. there is no such option to delete a existing node , how we can do that ?

Hi Nitesh,

If I understand your question correctly, this would be my suggestion:

How the nodes are linked

The nodes in the tree are simply linked by the relationship between the NodeId and ParentNodeIds. You can add rows to the AllNodesList input in any order, as long as the relationship between the Node and Parent is maintained. It will sort the nodes and assign the correct Nodes under the same parent if they share the ParentNodeId


How to add a node

You can simply use the List Append client action to add a new node to the list being used at the AllNodesList input to the tree. In this list append, just be sure that the new NodeId is unique in the tree and that the ParentId is the NodeId of the 'Parent' you want it to be a child of.

This is good enough if you want to add a new node without existing children. If you would like to add a new parent where there are already children, you will have to insert the new Parent node as described above, but then you will also have to filter through the old parent's children and update their ParentNodeId's.

1. Add new parent node with List Append

2. Filter tree input on ParentNodeId = ParentNodeId of node just added

3. Loop through filter results and update their ParentNodeId with the NodeId of the new parent (excluding the new parent node just added)


How to delete a node

Similar to adding a node, you can make use of the List Remove. You will however need to get the index by using ListIndexOf first. 

After removing the node, it is important that you again filter through the children of the node you just removed, if applicable, and update their ParentNodeIds to the NodeId of the parent of the node that was just removed. If the node did not have children, you can simply remove the node.

1. Remove existing parent node with List Remove

2. Filter tree input on ParentNodeId = NodeId of node just removed

3. Loop through filter results and update their ParentNodeId with the ParentNodeId of the node just removed


These actions can be linked to icons/links in the tree if you would like to make it part of the tree.

Hope this helps, let me know if anything is unclear.

Regards,

Heinri