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

loadOnDemand and checkChildren and template change

5 Answers 229 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Simone
Top achievements
Rank 1
Simone asked on 17 Feb 2015, 02:46 PM
I'm trying to wrap my head on using TreeView with options set to checkChildren=false and checkboxes.checkChildren=true. See the attached code, for simplicity it is derived from the TreeView / Checkboxes demo. Actual program has a larger tree all loaded at startup, and one day it may be loaded progressively.

1) Setting loadOnDemand=false, checking the non-expanded root the children are not seen by the checkedNodeIds().

2) Visiting the tree with the visitHDS(...) (Visit Tree button) function once the hierarchical datasource is bound to the tree changes the behaviour and checkedNodeIds() reports all checked children.

3) The "Change Template" button trigers template change function ( $("#change").click(function() { ...} ) tha uses treeView.setOptions(...). To force the update the tree treeView.setDataSource(...) method is used.

Some questions/observations:
a) Is it the intended behaviour?
b) Setting loadOnDemand=false makes the template change faster, also, in the future the tree may be loaded lazily from server.
c) Should I use an alternative function to checkedNodeIds?
d) Why visitHDS(...) "fixes things up? Why it works only after the hierarchical datasource is used by a tree.
e) Is there a better method for rerendering the tree after the template change  than treeView.setDataSource? (tried treeView.dataSource.read() but it is not faster and quite distruptive.

5 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 19 Feb 2015, 04:00 PM

Hello Simone,

The checkChildren functionality checks tree nodes that have been loaded. The loadOnDemand option, when set to true, does not load sub levels. The checkChildren functionality works with the loadOnDemand option -- when you load new nodes, it attempts to resolve conflicts based on the newly loaded data and the data that was on the page so far. This should clear things up so that it answers questions (a) and (b).

As for question (c), it depends on what you are trying to do. If nodes are not loaded, the checkedNodeIds will not report them as checked, since the TreeView does not know about them.

(d) The visitHDS method loads all levels -- this means that it does what loadOnDemand: false does.

(e) Dynamic changes in the template are not officially supported, but the setDataSource method should re-render the complete tree, so it is an acceptable workaround.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simone
Top achievements
Rank 1
answered on 16 Mar 2015, 04:31 PM
A question:

why visitHDS works only after the Hierarchical Datasource is bound to a tree, before it does not load the children?

In general. how to visit a Hierarchical Datasource ?
0
Accepted
Alex Gyoshev
Telerik team
answered on 18 Mar 2015, 09:05 AM

Hello Simone,

Can you please rephrase the question? The visitHDS method loads all children, by calling the load method. If you want to iterate through all items without loading items that are not loaded, do not call the load method.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simone
Top achievements
Rank 1
answered on 18 Mar 2015, 04:54 PM
I hope to explain myself better this time.

Calling visitHDS after creating the Hierarchical Datasource but before assigning to the kendoTreeView it does not traverse the tree. 

In the updated example visitMessage calls visitHDS to gather the nodes and create a message with the nodes list.
When called in (4) test.html:133 with "$("#visitResultBefore").html(visitMessage());" before creating the tree with $("#treeview").kendoTreeView({ ... }); it does nothing.
When calling it after the tree widget is created in test.html:169 as callback to the $("#visit").click(...) it traverses the tree and gathers the nodes.
0
Accepted
Alex Gyoshev
Telerik team
answered on 20 Mar 2015, 07:24 AM

Hello Simone,

Thank you for taking the time to describe the problem. The visitHDS does not work initially because the DataSource is not read before calling view(), i.e. no data has been fetched on the root level. Thus, view() will return an empty array and no child rows will be loaded. This can be resolved by calling either the DataSource fetch or read methods, prior to visiting the TreeView. Here is the updated sample.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
Simone
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Simone
Top achievements
Rank 1
Share this question
or