Expand all nodes in TreeView?

3 posts, 1 answers
  1. Bob
    Bob avatar
    29 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:
    It says, "Create a button for it and add event onclick like below (b is counter of not expand node):"

    $("#expandAllNodes").click(function (e) {
        function expandNextLevel() {
            setTimeout(function () {
                var treeview = $("#treeview").data("kendoTreeView");
                var b = $('.k-item .k-plus').length;
                if (b > 0) {
             }, 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?


    Bob Mathis

  2. Answer
    Alex Gyoshev
    Alex Gyoshev avatar
    2515 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;

    Alex Gyoshev

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

  3. Bob
    Bob avatar
    29 posts
    Member since:
    Dec 2014

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


    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.



Back to Top