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

[Solved] Expand single node onClick

2 Answers 83 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.
Howard
Top achievements
Rank 1
Howard asked on 18 Jan 2012, 05:14 AM
Hi telerik support,

I am using First Look TreeView and i am trying to make only single node is expanded at a time i.e only the clicked node gets expanded and other is collapsed, but couldn't do so, could you please help me with this.

I have seen the same fuctionality in PanelBar(Client-side API), can we do same expand/collapse in treeview also?

Regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 19 Jan 2012, 05:13 PM
Hi Niroj,

This functionality is not supported out-of-the-box and to achieve it you can use the following approach
  1. Hook a JavaScript function to the OnExpand client event (e.g. expand).
  2. In the function close all the siblings on the same level (using the collapse method), recursively close all the parent's siblings.
    e.g.
    <script type="text/javascript">
        var procesing = false;
     
        function expand(e) {
            if (!procesing) {
                procesing = true;
                var tree = $('#TreeView').data('tTreeView')
                 
                closeSib($(e.item),tree)
                procesing = false;
            }
        }
     
        function closeSib($element,tree) {
            var $siblings = $element.siblings();
            tree.collapse($siblings);
            if ($element.parent('li').length>0) {
                closeSib($element.parent('li'), tree);
            }
        }
    </script>

Regards,
Petur Subev
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
Howard
Top achievements
Rank 1
answered on 23 Jan 2012, 02:07 AM

Thanks Petur !

Excellent! that works.
Tags
TreeView
Asked by
Howard
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Howard
Top achievements
Rank 1
Share this question
or