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

onDataBound fires before the data loads

5 Answers 97 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Veteran
Matt asked on 30 Jul 2020, 04:20 PM

I have several treeviews on a page and the ondatabound is firing before the data is loaded, actually, before the tree is ready. Anything that I need to do differently?

 

Matt

5 Answers, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 04 Aug 2020, 01:23 PM

Hi Matt,

The dataBound event is being triggered after each data binding. This means that it will first be triggered when the top item levels are loaded and then again for each node that has children and which is being extended. If the component is configured with a loadOnDemand property set to "false" this means that initially the dataBound event will be triggered "X" times, where "X" is the number of sub-items(levels) that should be loaded inside the TreeView in order to have all its data items loaded. The described behavior with "loadOnDemand:true" can be observed in this Dojo example

If you want to trigger an event when all TreeView data is loaded, you will have to manually check if all dataSource sub-levels are loaded. If this condition is met, you can continue with your logic. This can be achieved using the dataItem method. Based on the "hasChildren" property of the value that the dataItem method returns you can loop through all nodes and if there are no more children to load, you can continue with the execution of the additional logic. 

Regards,
Petar
Progress Telerik

0
Matt
Top achievements
Rank 1
Veteran
answered on 04 Aug 2020, 03:44 PM

ok, fair enough, but how then is it that if I change the alert to:               

alert("DataBound, total records="+$("#treeview").data("kendoTreeView").dataSource.total());

total() only ever shows 1. Should it not show the total amount of records in the datasource? the loadOnDemand property has no impact on this either.


0
Matt
Top achievements
Rank 1
Veteran
answered on 04 Aug 2020, 05:10 PM
One other thing: Can you please check this with the .Net Core version?
0
Petar
Telerik team
answered on 07 Aug 2020, 03:08 PM

Hi Matt,

I will need some time to test the reported behavior with the TreeView's dataSource.

I will write you back on Monday with more details about the current issue. 

Regards,
Petar
Progress Telerik

0
Petar
Telerik team
answered on 10 Aug 2020, 08:44 AM

Hi Matt,

The reported behavior of the total() method is expected. In the context of the hierarchical dataSource the total method returns the length of the parent node that was expanded. This length will always be 1 as we are expanding one node at a time. I've also tested the same scenario in the context of ASP.NET Core and the result is the same. 

If you want to count the total number of items loaded in the TreeView, I would suggest trying the approach discussed in this forum reply.

I have also logged a feature request for a method that returns the number of the total items/nodes loaded in the TreeView. This request can be followed on this link: https://feedback.telerik.com/aspnet-core-ui/1479811-add-method-that-returns-the-total-number-of-the-loaded-items-in-a-hierarchical-datasource

I cannot say if and when the request will be implemented. It all depends on the community interest in it and our priority queue. What you can do is to vote for the request. The more votes a given request has, the bigger the chance for its sooner implementation is. 

Regards,
Petar
Progress Telerik

Tags
TreeView
Asked by
Matt
Top achievements
Rank 1
Veteran
Answers by
Petar
Telerik team
Matt
Top achievements
Rank 1
Veteran
Share this question
or