loadOnDemand and checkChildren and template change

6 posts, 3 answers
  1. Simone
    Simone avatar
    9 posts
    Member since:
    Jul 2014

    Posted 17 Feb 2015 Link to this post

    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.
  2. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 19 Feb 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Simone
    Simone avatar
    9 posts
    Member since:
    Jul 2014

    Posted 16 Mar 2015 in reply to Alex Gyoshev Link to this post

    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 ?
  5. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 18 Mar 2015 Link to this post

    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!
     
  6. Simone
    Simone avatar
    9 posts
    Member since:
    Jul 2014

    Posted 18 Mar 2015 in reply to Alex Gyoshev Link to this post

    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.
  7. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 20 Mar 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready