To edit title (or other hidden fields) of a node, you need to :
(1). get the node from your tree data by calling getNodeAtPath()
(2). edit the fields of the retrieved node
(3). call your_react_component.setState()
to re-render the tree view,
For example:
import SortableTree, {getNodeAtPath} from 'react-sortable-tree';
...
export default class your_react_component extends Component {
// ...... other functions like constructor , etc.
getNodeKey(node) {
// this example uses tree index as node key
return node.treeIndex;
}
update_tree_status(evt) {
// the function is an event handler of a button click for each node
// step #1 : first retrieve path of the target node
var btn_dom = evt.nativeEvent.target;
var path = btn_dom.dataset.node_key_path;
path = path.split(',');
path = path.map(key => parseInt(key));
// step #2: get the node object
let found_node = getNodeAtPath({
treeData: this.state.treeData,
path : path, // list of tree indexes on the editing node
getNodeKey: this.getNodeKey
});
// step #3: updating title or other fields of the node
// step #4: re-render the tree view
this.setState({treeData : this.state.treeData})
}
// ..................
render() {
return <SortableTree isVirtualized={ false }
treeData={this.state.treeData}
onChange={this.on_state_change.bind(this)}
generateNodeProps={
({node, path, treeidx}) => ({
title: node.title,
buttons: [
<button data-node_key_path={ path.join(',') }
onClick={ this.update_tree_status.bind(this) }>
edit
</button> ,
],
})
}
/> ;
} // end of render function
};