How to show the images in treeview on expand and collapse nodes in react.js?

How to show the images in treeview on expand and collapse nodes in react.js? Important

Hi, I am new to react.js. Please help me. I create a treeview control using react.js from XML file. On page load, its showing two main parent nodes only (Collapse plus image). Clicking on + or node click expand node. Parent node will have minus image. All the nodes having children who are expanded will have minus image.

Collapse nodes plus image

expand nodes having child will have minus image.

last node will have paper image. 

Please find the code in the attachment with the images and tree.gif displays how tree looks like. 

Please modify the code, how to use images. Currently it's showing unordered list.

Thanks for all the help.


Attachment: tree_new_2_589155e8.zip

1 Reply

KR Keerthana Rajendran Syncfusion Team November 1, 2021 06:55 AM UTC

Hi Customer,  
  
Thanks for contacting Syncfusion support. 
 
We checked your attached code and couldn’t find any Syncfusion TreeView code in the shared files. However, we have prepared a React sample for including “plus” and “minus” icons for Syncfusion TreeView.  
  
Refer to the following code.  
  
export class Default extends SampleBase {  
  constructor() {  
    super(...arguments);  
    this.data = dataSource;  
    this.fields = {  
      dataSource: this.data.defaultData,  
      id: "id",  
      text: "name",  
      child: "subChild"  
    };  
    this.style = "custom";  
  }  
  render() {  
    return (  
      <div className="control-pane">  
        <div className="control-section">  
          <div className="tree-control_wrapper">  
            <TreeViewComponent fields={this.fields} cssClass={this.style} />  
          </div>  
        </div>  
      </div>  
    );  
  }  
}  
  
CSS:  
  
.custom.e-treeview .e-list-item .e-icon-expandable::before {  
  content: '\e556';  
  font-size: 13px;  
}  
.custom.e-treeview .e-list-item .e-icon-collapsible::before {  
  content: '\e554';  
  font-size: 13px;  
}  
  
Refer to the sample link for Syncfusion React TreeView.  
  
  
Using nodeTemplate option, the required icons(paper icon) or HTML element can be added within TreeView node.  
  
  
  
Refer to the following UG link for icons library available with Syncfusion.  
  
  
Note: We have shared the response based on Syncfusion components. Please revert if you encounter any issues with Syncfusion components.  
  
Regards,  
Keerthana R.  


Loader.
Up arrow icon