Expand all nodes in TreeView?

3 posts, 1 answers
  1. Bob
    Bob avatar
    24 posts
    Member since:
    Dec 2014

    Posted 04 May 2015 Link to this post

    I have a couple of TreeViews on a razor page, one of which has at least 10 levels.
    I need to be able to expand, collapse, and search each of the trees.
    I found the following on the forums that supposedly expands the TreeView and it does work - kind of:
    http://www.telerik.com/forums/is-there-a-way-to-expand-all-nodes-in-multiple-level-for-treeview#Of6kvLQLNE-YgOdLSPjUlA
    It says, "Create a button for it and add event onclick like below (b is counter of not expand node):"

    $("#expandAllNodes").click(function (e) {
            e.preventDefault();
            expandNextLevel();
        });
        function expandNextLevel() {
            setTimeout(function () {
                var treeview = $("#treeview").data("kendoTreeView");
                var b = $('.k-item .k-plus').length;
                treeview.expand(".k-item");
                treeview.trigger('dataBound');
                if (b > 0) {
                    expandNextLevel();
                }
             }, 200);
        }

    Is always hit, because, at least in my case, the value of b is never less than 4.
    So I need some comparison that will tell me that the tree has been completely examined and then it will stop.
    Does anyone know how I can do that?

    TIA,

    Bob Mathis

  2. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 05 May 2015 Link to this post

    Hello Bob,

    Instead of getting all plus icons on the page, get them only for the said TreeView:

    // the line 
    var b = $('.k-item .k-plus').length;
    // should be
    var b = treeview.element.find('.k-item .k-plus').length;

    Regards,
    Alex Gyoshev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Bob
    Bob avatar
    24 posts
    Member since:
    Dec 2014

    Posted 05 May 2015 in reply to Alex Gyoshev Link to this post

    Wonderful.

    Thank you so much. Trying to figure some of these things out are really difficult, but this forum (and especially you admins) are a lifesaver.

     

    Bob

Back to Top