frontend-collective / frontend-collective/react-sortable-tree
[HELP] How to get the index of the children when dragging
- Dominant language
- JavaScript
- Stars
- 5k
- Forks
- 914
- PR merge metrics
- No merged PRs in 30d
Description
How can i get the index inside every node children when dragging so i can set the weight of the category? Right now I'm able to change the parent and the path in the categories, but can't figure how to find the proper weight according to the order that i set via dnd.
Example (inside brackets is the index)
```
--Parent [0]
-- Children [1]
--GrandChildren One [let's say 0]
--GrandChildren Two[let's say 1]
```
Ho can i get the index (when dragging finishes) of `GrandChildren One` and `GrandChildren Two` in order to set it in `weight` property?
```
changeNodeAtPath({treeData: this.state.treeData, path: args.path, getNodeKey: ({node}) => node._id, newNode: {...args.node, parent: args.nextParentNode._id, path: args.path.join('/'), weight: args.nextTreeIndex}});
```
Here's an example [CodeSandbox](https://codesandbox.io/s/8zqjxmv5p8)
possible dup of #153 but I want to avoid filtering the whole tree.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.