Hi All
I am adding some sub nodes below treeitems a various levels and I find that they appear at the end of the tree rather than under the parent that they are added (treeitem.items).
Is there a way to for full tree re render?
I am currently recreating the tree data to add the new child item and updating the state that is bound to the data for the treeview. Is there something else that I would need to do?
Code used to update the tree state:
const [tree, setTree] = React.useState<TreeViewDataItem[]>([]);
let newTree: TreeViewDataItem[] = [];
let newTreeParent: TreeViewDataItem = InsertTreeItem(tree[0], newTreeItem, parentTreeItem.index);
newTree.push(newTreeParent);
setTree(newTree);
export const InsertTreeItem = (treeItem: TreeViewDataItem, newItem: TreeViewDataItem, parentIndex: number): TreeViewDataItem => {
let newItems: TreeViewDataItem[] = [];
treeItem.items.forEach((node) => {
if (node.index == parentIndex) {
node.items.push(newItem);
}
let cloneNode: TreeViewDataItem = _.cloneDeep(node);
newItems.push(cloneNode);
InsertTreeItem(node, newItem, parentIndex);
});
treeItem.items = newItems;
return treeItem;
}
<TreeView data={tree}
expandIcons={true}
item={fetchTreeItemView}
onExpandChange={onExpandChange}
onItemClick={onTreeItemClick} />
Thanks for your help.