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

Disable parent node(dynamic) click in radtreeview

6 Answers 231 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 11 Dec 2013, 08:12 AM
Hi,
i am using rad treeview,so how can i Disable parent node(dynamic) click in radtreeview.
Thanks

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Dec 2013, 10:14 AM
Hi Swapnil,

Please have a look into the following JavaScript to disable the click of RadTreeView parent node.

JavaScript:
<script type="text/javascript">
    function pageLoad() {
        var tree = $find("<%=RadTreeView1.ClientID %>");
        for (var i = 0; i < tree.get_allNodes().length; i++) {
            if (tree.get_allNodes()[i]._hasChildren() == true) {
                tree.get_allNodes()[i].set_enabled(false)
            }
        }
    }
</script>

Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 12 Dec 2013, 09:57 AM
i dont want like this,
i am having parentnode as company name and child node as entityname
onclick of that entityname it goes in click event giving entityname,thats why dont click on parent node
Thanks.
0
Shinu
Top achievements
Rank 2
answered on 16 Dec 2013, 05:42 AM
Hi Swapnil,

I guess you want to disable the click event of RadTreeView Parent node. Please have a look into the following code snippet which works fine at my end.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeClicking="OnClientNodeClicking1"
    DataFieldID="id" DataFieldParentID="parentid" DataTextField="text" DataSourceID="SqlDataSource1">
</telerik:RadTreeView>

JavaScript:
<script type="text/javascript">
    function OnClientNodeClicking1(sender, args) {
        if (args.get_node()._hasChildren() == true) {
            args.set_cancel(true);
        }
        else {
            alert(args.get_node().get_text());
        }
    }
</script>

Let me know if you have any concern.
Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 17 Dec 2013, 06:11 AM
this is working fine in the case where parent node having child node
but in case of single parent node it is clicking to that node
Thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Dec 2013, 08:33 AM
Hi Swapnil,

Please have a look into the following code snippet.

JavaScript:
<script type="text/javascript">
    function OnClientNodeClicking1(sender, args) {
        var node = args.get_node();
        if (node.get_parent() == node.get_treeView() || args.get_node()._hasChildren() == true) {
            args.set_cancel(true);
        }
        else {
            alert(args.get_node().get_text());
        }
    }
</script>

Thanks,
Shinu.
0
Accepted
Nencho
Telerik team
answered on 17 Dec 2013, 09:16 AM
Hello,

The Shinu's suggestion is correct and applicable. Another possible approach to determine if the currently selected node is a parent is by verifying if the parent node (get_parent()) has an id. If it does - it would mean that a reference to the RadTreeView is obtained and this node is a root node:
                 var isParent;
 
            if (args.get_node().get_parent().get_id != undefined) {
                isParent = true
            }


Regards,
Nencho
Telerik
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 RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
TreeView
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or