This is a migrated thread and some comments may be shown as answers.

Load treeview children on demand/condition

7 Answers 1106 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Daochuen asked on 03 Jan 2019, 10:16 PM

Hello,

Would someone be able to offer the solution on how to get certain node's data which is dynamic loaded (load on demand)?

The case is that in my MVC project the top level node have already be loaded on TreeView . I need load second level to fourth level node based on every level's condition (on one button click). My problem is I cannot get second level's detail data (after the nodes appended to top level ) which third level depend on. When I do the debug the count of second level nodes showed correctly, but not detail data anywhere. Do you have some suggestions? Thanks in advance!

7 Answers, 1 is accepted

Sort by
0
Accepted
Joana
Telerik team
answered on 07 Jan 2019, 03:24 PM
Hello,

Based on the data and the information you have about the node that needs to be expanded on a button click, you could

1) Use the expandPath methods of the TreeView:

https://docs.telerik.com/kendo-ui/api/javascript/ui/treeview/methods/expandpath - This method would be the best approach if you are aware of the ids of all node's parents or you could easily find its dataItem parents based on certain criteria.

2) Consequentially expand only the items and locate the node:

https://docs.telerik.com/kendo-ui/controls/navigation/treeview/how-to/nodes/node-async-expand

I hope this will help you achieve your scenario.

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 08 Jan 2019, 05:40 AM
Thanks for respond.

After further analysis I found loaded children items be doubled.  For example, one node have two children but items showed 4. Items[0] and items[1] contain some none- useful data which I investigated before. Items[3] and items[4] did include real  detail data. I don't know why data showed in that way but I get the data back by reading the last two elements.

0
Joana
Telerik team
answered on 09 Jan 2019, 03:32 PM
Hi,

I cannot think of any reason to have duplicated data items in the TreeView. Are you sure that the hierarchy of the items is correct?

Could you please share a runnable sample where we could examine the issue in order to give you more useful information? 

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 13 Jan 2019, 11:31 PM

Hi Joana, 

Somehow I don't know why the extra dummy nodes occurred during the run-time. After I had modified the node loading function, the extra nodes have gone but my initial problem appears again - I can't get the node id after nodes were loaded in one process, resulting in deeper level nodes not be loaded.

I created two files to reproduce the issue:
 
1. TreeViewTestController, server side code which includes sample class Employee to made tree nodes
2. Index.cshtml file with JavaScript on the bottom.

Steps to reproduce:
After index shown top node with two direct children are loaded.
1. select top Node "CEO" if it is not highlighted( see first image on attached doc file)
2. put 7 (Fifth level note  id) in the text box 
3. click button "Load this child"

Program should load Level3, level4 and level5 in turn, eventually hit level 5 node with id="7" 

But the program stops at level two (see third image on attached doc file) since id field is empty for every loaded field. But if I uncomment statement alert("After this message you could see loaded nodes and nodes data") within function doLoadChildredNode(), all the nodes are loaded as expected ( see second image on attached doc file). 

My question is that how do I load all the level nodes without alert() statement ?

Really appreciate your time and help. This issue bother me a lot.

0
Joana
Telerik team
answered on 16 Jan 2019, 06:35 AM
Hello,

Thanks for providing your files.

I'll go through them and let you know my findings.

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Accepted
Joana
Telerik team
answered on 16 Jan 2019, 10:31 AM
Hello Zhihong,

The matter of issue is that the loading of child nodes is asynchronous operation and you have to wait for it to complete before executing further logic. 

Having an alert statement pauses the execution, and thus the logic for expanding next levels work. So, I would suggest the implementation of asynchronous loading and expanding of the children as shown in the below article:

https://docs.telerik.com/kendo-ui/controls/navigation/treeview/how-to/nodes/node-async-expand


Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 18 Jan 2019, 08:58 PM
Thank you so much Joana,  After I changed my code based on your suggestion I got the expected results back!
Tags
TreeView
Asked by
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Joana
Telerik team
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or