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

[Solved] Accessing the "expanded" flags of the nodes in a currently existing tree

1 Answer 124 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 15 Nov 2011, 09:14 PM
I have a tree with load on demand data binding set up. The tree represents a file structure, and every time the user uses the page it's on to alter the file structure, I rebind the tree completely. (I do this to avoid problems outlined here) That works out fine and all, except for the fact that it causes the tree to completely collapse. This could be annoying for the user, so I wrote some code in my action method the tree data binding points to. This code takes in the root node of the previous structure (passed in through ajaxRequest() in javascript upon completion of a file system altering event) and basically attempts to set the "expanded" flag in every new node based on the flag of comparable nodes in the old structure.

To my dismay, I quickly discovered that apparently the node that is passed to my action controller by ajaxRequest() has its expanded flag always set to false. The same goes for all of its sub nodes. So apparently ajaxRequest() doesn't even bother to pass that information along. Is that the way its supposed to work? It would be pretty handy if that info got passed along, I gotta admit.

Thinking about it some more, I thought maybe I'd try and see if I could look at expanded flag of tree nodes in javascript, before I call ajaxRequest(). But I have no idea where to look. Where is that flag stored? Is it stored anywhere at all? Can I even get the current "expanded" flags of nodes in an existing tree, or am I out of luck in that department? If so, why? That seems like it'd be a useful feature.

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 17 Nov 2011, 01:36 PM
Hello Jonathan,

The TreeView does not have any internal state that describes the expanded nodes. However, you can gather them pretty easy with jQuery, like this:

// gathers all items that have a "minus" icon
var expandedItems = $(".t-minus").closest(".t-item");

Kind regards,

Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
TreeView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or