Datasource not updating after append

2 posts, 1 answers
  1. Niranjan
    Niranjan avatar
    11 posts
    Member since:
    Sep 2017

    Posted 18 Jan 2018 Link to this post

    I have a tree with 5 levels => L1, L2, L3, L4 & L5, the tree implements lazy loading. Hence only L1 level nodes are currently in the datasource.

    I accept an input from the user that has 5 Id's. Each of which corresponds to one level of the tree. EX : Id1 => L1, Id2 => L2 and so on...
    Then,

            var treeview = $("#treeView").data("kendoTreeView");
            var dataSource = treeview.dataSource;
            var data = dataSource.get(Id1);
            var levelonenode = treeview.findByUid(data.uid);
            // Logic to append the child nodes of levelonenode (with one of the child nodes having id =Id2)

    //now when i check the debugger, the append operation is complete but the dataSource shows that levelonenode doesn't have any children yet.

           var leveltwodata = dataSource.get(Id2);
    //does not exist

    I suspect that the children have been appended but havent yet been rendered on the UI so the dataSource hasnt been refreshed.

    Is there a workaround for this?

    Any help would be appreciated!

    Thanks,
    Niranjan.


  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    806 posts

    Posted 22 Jan 2018 Link to this post

    Hello Niranjan,

    The Kendo UI TreeView uses hierarchical data. When configured with loadOnDemand set to true, children nodes are being loaded lazily (remote request is triggered upon expanding a node that retrieves the data). The DataSource of the widget contains information about the currently loaded dataItems. Each dataItem has a children property, which will be populated with data only if it is already loaded from the remote service (node is expanded).

    You can verify that this is the case by subscribing to the TreeView's dataBound event, where you can get currently loaded dataItems with the e.sender.dataSource.data() method and process them further according to your requirements. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top