react-sortable-tree icon indicating copy to clipboard operation
react-sortable-tree copied to clipboard

How to set background color of each node in react-sortable-tree package

Open M4Lien opened this issue 6 years ago • 4 comments

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.)

M4Lien avatar Nov 19 '18 06:11 M4Lien

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

M4Lien avatar Nov 19 '18 06:11 M4Lien

How do you go about this?

ut2k avatar Aug 11 '20 21:08 ut2k

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

thayllo-co avatar Feb 22 '21 18:02 thayllo-co

This solution is not working

Punith13 avatar Oct 12 '21 21:10 Punith13