This is a migrated thread and some comments may be shown as answers.

Expand all nodes in TreeView?

2 Answers 344 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 2
Bob asked on 04 May 2015, 05:51 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 05 May 2015, 10:48 AM

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.

 
0
Bob
Top achievements
Rank 2
answered on 05 May 2015, 01:30 PM

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

Tags
TreeView
Asked by
Bob
Top achievements
Rank 2
Answers by
Alex Gyoshev
Telerik team
Bob
Top achievements
Rank 2
Share this question
or