Dynamically load TreeList sub-items

1 Answer 27 Views
TreeList
Bernd
Top achievements
Rank 5
Bronze
Bronze
Bronze
Bernd asked on 10 Jun 2024, 01:22 PM

I would like to dynamically load the sub-items of a TreeList whenever the triangle infront of an element is clicked to open the sub-item and then fetch the sub-items from an API. I guess I need to use the onExpandChange event for this, correct? Do you have an example on how I would have to extend the original tree when the sub-items have loaded?

Any hints would be greatly appreciated.

Thanks,

Bernd

1 Answer, 1 is accepted

Sort by
1
Accepted
Vessy
Telerik team
answered on 12 Jun 2024, 08:50 AM

Hello, Bernd,

You can load the nested items when a TreeView rows are expanded by implementing a similar approach:

As assumed by you, the items in the sample above are fetched each time an expand icon is clicked by handling the onExpandChange event. Please, give this suggestion a try and let me know in case I can assist you any further on this matter.

Regards,
Vessy
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

Bernd
Top achievements
Rank 5
Bronze
Bronze
Bronze
commented on 12 Jun 2024, 10:06 AM

Hi Vessy.

Thanks for the example. That's what I thought and I'll go from there and try it out.

Great support as always. :-)

Greetings,

Bernd

Vessy
Telerik team
commented on 12 Jun 2024, 10:54 AM

You are most welcome, Bernd :)

Thanks a lot for the kind words!

 

Bernd
Top achievements
Rank 5
Bronze
Bronze
Bronze
commented on 19 Jun 2024, 11:41 AM

Hi again.

I tried it out now and there is one more issue left for me. As I said, I want to load the sub-items of an item when the user clicks on the little triangle to expand the item. The issue is though, that if there are no sub-items in the items field, then the triangle doesn't show up, so the user of course can't click on it to load them. I would have to add a dummy item into each items field array to make this somehow possible and then replace the dummy field when the "real" sub-items are loaded but that seems to be a hacky "solution" to me. Is ther any way I can switch on the triangle without adding anything to the items field array?

Thanks,

Bernd

Vessy
Telerik team
commented on 21 Jun 2024, 05:39 AM

Hi, Bernd,

Your assumption is correct -  adding a dummy child item is the only way to trigger the arrow of the nodes with the current implementation of the TreeList.

Regards,

Vessy

Tags
TreeList
Asked by
Bernd
Top achievements
Rank 5
Bronze
Bronze
Bronze
Answers by
Vessy
Telerik team
Share this question
or