frontend-collective / react-sortable-tree

Drag-and-drop sortable component for nested data and hierarchies
https://frontend-collective.github.io/react-sortable-tree/
MIT License
4.9k stars 897 forks source link

Insert node at specific index under parent node.Iindex #930

Open amitmankotia opened 2 years ago

amitmankotia commented 2 years ago

I am using react-sortable-tree in my application to create a funnel. I have a use case where I have a two buttons on child node to create another node under and above it. I need a method where I can pass parentKey and index so that new node is create under parent at specific index.

image

I did not find any function like addNodeUnderParentAtIndex which can do so.

Any help on how this can be done is appreciated!

ths-somebody commented 2 years ago

You will need to create a clone the parent and place the new node the cloned parent node children. Then update the tree with this new parent node.