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

[Solved] Looking for the "expanded" flag

3 Answers 111 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.
Peter
Top achievements
Rank 1
Peter asked on 16 Nov 2011, 09:00 AM
hi,

In my tree view the user can expand a node by selecting the full item.

var tv = Html.Telerik().TreeView()

    .Name("Activiteit")

    .Items(item =>

                {
// Usual stuff here
                })

    .ClientEvents(e => e.OnSelect("ActiviteitGekozen"));

The js-function:

    function ActiviteitGekozen(e) {

        var treeView = $("#Activiteit").data("tTreeView");

        treeView.expand(e.item);

    }

Works like a charm.
Now I want to enriched this behavior by collapsing the item in case it was already expanded. No problem, treeView.collapse(e.item) will do just that.

My problem is how to determine the current state of the node. All I can google is this 'expanded' flag, no hints how to get it.
Any help appreciated
Peter

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 16 Nov 2011, 09:21 AM
Hi Peter,

The TreeView items do not have client objects that have information about their state. You can check whether an item is expanded or collapsed like this:

var isCollapsed = !$(item).find('> .t-group, > .t-content').is(':visible');

item is a TreeView item <li> DOM element.

All the best,
Dimo
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
0
Peter
Top achievements
Rank 1
answered on 16 Nov 2011, 09:42 AM
Works like a charm :)
For the sake of Google:

    function ActiviteitGekozen(e) {

        var treeView = $("#Activiteit").data("tTreeView");

         if ($(e.item).find('> .t-group, > .t-content').is(':visible'))

             treeView.collapse(e.item);

        else

            treeView.expand(e.item);

    }

Thank you.

Peter
0
Jonathan
Top achievements
Rank 1
answered on 16 Nov 2011, 04:05 PM
Oh, so this is where my answer went. Thanks dimu.

Though neither the "expanded" or "visible" flags seem to get carried along with the data passed into ajaxRequest(). Expanded is always set to false and visible is always set to true. I was kinda hoping I could do some state-copying server side using current data passed in from the client, but ajaxRequest() seems to omit that data for whatever reason, which is a little frustrating.

I guess I'll just have to figure out how to do it in javascript...

EDIT: Upon further inspection I've discovered that the TreeViewItem that the data binding action method receives from ajaxRequest doesn't even have child items, even if the item passed in did. I'm seriously curious as to why such a bare minimum of data is passed along in this transaction. Is there some fundamental reason, or have you simply chosen not to implement it? Or am I just doing something wrong?
Tags
TreeView
Asked by
Peter
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Peter
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
Share this question
or