We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

TreeView Data loading after dispatch is called

Hi,
I am trying to load data after api call.
I have created reducer and using connect as HOC. Once I will get data in my props I will use this data to load on treeview.
Please suggest some options to implement this functinality
Thanks,
Sonam Diwate

3 Replies

CI Christopher Issac Sunder K Syncfusion Team March 11, 2019 12:01 PM UTC

Hi Sonam, 

Thank you for contacting Syncfusion support. 

We have prepared a sample based on your requirement. Here we bind the dataSource to the treeview after the dispatch is called on button click. Please find the code snippet. 

loadTree: function () { 
    store.dispatch(Click()); 
    var tree = document.getElementById("tree").ej2_instances[0]; 
    tree.fields.dataSource = store.getState(); 
    tree.dataBind(); 
} 

Please find the sample from the following link. 

You can use the following comments to make the sample runnable. 
  1. npm install
  2. npm install react-scripts --save
  3. npm start

Please check the sample and let us know whether it fulfills your requirement. 

Thanks, 
Christo


SD Sonam Diwate March 12, 2019 12:47 PM UTC

Thanks for quick reply.


But here I want to bind nodeTemplate also. as we need to use custom templates.
Also I want to restrict some of child nodes to drag and drop as well as select node

Thanks,
Sonam Diwate


CI Christopher Issac Sunder K Syncfusion Team March 12, 2019 12:52 PM UTC

Hi Sonam, 

We have prepared sample for binding datasource along with nodeTemplate. Please find the code snippet 

loadTree: function () { 
    store.dispatch(Click()); 
    var tree = document.getElementById("tree").ej2_instances[0]; 
    tree.fields.dataSource = store.getState(); 
    tree.cssClass = "custom"; 
    tree.nodeTemplate = '<div><img class="eimage" src="https://ej2.syncfusion.com/demos/src/images/employees/${eimg}.png\" alt="employee"/><div class="ename"> ${name} </div><div class="ejob"> ${job} </div></div>'; 
    tree.dataBind(); 
} 

Please check the sample from the following link and get back to us if you need any further assistance. 

Thanks, 
Christo

Loader.
Up arrow icon