problem restoring tree view on document ready

2 posts, 0 answers
  1. Luis
    Luis avatar
    6 posts
    Member since:
    Sep 2015

    Posted 25 Jul Link to this post

    Hello I'm trying to load a load on demand tree on document.ready according to a path like shows this jsbin:

    http://jsbin.com/ESOjAmi/8/edit?html,css,output

    The problem in my case is that exist child nodes that have the same id as parents, because are two different entities, so in those cases the parent is expanded but the children that i want to select and trigger the select event is not selected i guess because the method get in the datasource returns the first node that match the id.

    The problem is in this part of the code because in the case of the path [1,1] for example it expands the parent node but not the children with id 1 and i want to trigger the select event of the children node.

     else {
            // otherwise select
            node = treeview.findByUid(ds.get(path[0]).uid);
            treeview.select(node);
            treeview.trigger("select", { node: node });
          }

    Maybe you can modify the example to reflect my case please?

    Thank you

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 27 Jul Link to this post

    Hello Luis,

    Indeed the DataSource's get method will return only the first node that has an id matching the passed id. What you can do is check whether the parent contains a child node with id the same as its parent's and select that child, for example:
    else {
            if (node.hasChildren) {
                var childrenView = node.children.view();
                for (var i = 0; i < childrenView.length - 1 ; i++) {
                    if (childrenView[i].id == path[0]) {
                        node = treeview.findByUid(childrenView[i].uid);
     
                    }
                    else {
                        node = treeview.findByUid(ds.get(path[0]).uid);
                    }
                }
            }
            else {
                node = treeview.findByUid(ds.get(path[0]).uid);
            }
     
            treeview.select(node);
            treeview.trigger("select", { node: node });
        }


    Regards,
    Ivan Danchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top