react-sortable-tree
react-sortable-tree copied to clipboard
How to set background color of each node in react-sortable-tree package
Reporting a Bug?
Please include either a failing unit test or a simple reproduction. You can start by forking the CodeSandbox example
Requesting a Feature?
Provide as much information as possible about your requested feature. Here are a few questions you may consider answering:
- What's your use case? (Tell me about your application and what problem you're trying to solve.)
- What interface do you have in mind? (What new properties or methods do you think might be helpful?)
- Can you point to similar functionality with any existing libraries or components? (Working demos can be helpful.)
Hi, how are you? I have faced a problem for setting background of each node. I have implemented another method for setting background, But I can't set it. Can you help me? thanks
How do you go about this?
You have to set an style inside the generateNodeProps, this is going to apply defined style in the row tag of each node, as the example below:
<SortableTree
treeData={this.state.treeData}
onChange={treeData => this.setState({ treeData })}
generateNodeProps={({ node, path, treeIndex }) => ({
onClick: () => { /* YOUR CLICK DEFINITION*/ },
title: ( /* YOUR TITLE DEFINITION*/ ),
// THE STYLE THAT YOU WANNA PUT INTO YOUR NODE
style: { backgroundColor: (node.id === this.state.selectedNodeId) ? 'rgba(0, 0, 0, 0.1)' : 'white' }
})}
/>
You can also define styles for each node conditionally, as the example
This solution is not working