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

TreeViewNode display

2 Answers 41 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
mn moule
Top achievements
Rank 1
mn moule asked on 06 Jul 2010, 11:06 AM
Hi Friends,

I have a RadTreeView Control and i use xml datasource binding.
i have a textbox above the treeview control.
When a type a word/node name in the textbox. i want my treeview to be binded only upto that node hierarchy. not its child details.

for ex:
consider a tree having A as parent its direct child is B and Its direct child  be C.
so if i search for B
Tree should only display A and its child B. since B is the node that i searched for.

Examples would be appresiated.

One more thing is . how to set the datasource proiperty for the RadTreeView control in javascript.

2 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 08 Jul 2010, 01:11 PM
Hello mn moule,

I have prepared example which I think will be most appropriate for your requirements.
I am not binding the tree accordingly to the searchText, instead I am collapsing the tree and showing only the searched Node (if any).
Here is the markup:
<telerik:RadTextBox runat="server" ID="txtSearch">
    <ClientEvents OnKeyPress="onKeyPress" />
</telerik:RadTextBox>
<telerik:RadTreeView ID="RadTreeView1" runat="server">
    <Nodes>
        <telerik:RadTreeNode Text="Root1">
            <Nodes>
                <telerik:RadTreeNode Text="Child 1.1">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 1.1.1" />
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 1.2">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 1.2.1" />
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 1.3">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 1.3.1" />
                    </Nodes>
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode Text="Root2">
            <Nodes>
                <telerik:RadTreeNode Text="Child 2.1">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 2.1.1" />
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 2.2">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 2.2.1" />
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 2.3">
                    <Nodes>
                        <telerik:RadTreeNode Text="Child 2.3.1" />
                    </Nodes>
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

And the javaScript:
function onKeyPress(sender,args) {
    setTimeout(function () {
        var tree=$find('<%= RadTreeView1.ClientID %>')
        var textBox=sender;
        var text=textBox.get_textBoxValue();
 
        var nodeWithThisText=tree.findNodeByText(text);
        if(nodeWithThisText!='undefined'&&nodeWithThisText!=null) {
            collapseNodesInCollection(tree.get_nodes());
 
            var parentNode=nodeWithThisText.get_parent();
            for(var i=0;i<nodeWithThisText.get_level();i++) {
                parentNode.set_expanded(true);
                parentNode=parentNode.get_parent();
            }
            setTimeout(function () { nodeWithThisText.set_selected(true); },0);
        }
    },0);
}
 
function collapseNodesInCollection(children) {
    for(var i=0,count=children.get_count();i<count;i++) {
        var node=children.getNode(i);
        collapseNodesInCollection(node.get_nodes());
        node.set_expanded(false);
    }
}

Hope this is helpful for you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
mn moule
Top achievements
Rank 1
answered on 08 Jul 2010, 01:26 PM
Hi Nikolay,
Thanks for your reply. will let u know once implementing it.
Tags
TreeView
Asked by
mn moule
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
mn moule
Top achievements
Rank 1
Share this question
or