Disable parent node(dynamic) click in radtreeview

7 posts, 2 answers
  1. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 11 Dec 2013 Link to this post

    Hi,
    i am using rad treeview,so how can i Disable parent node(dynamic) click in radtreeview.
    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Dec 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 12 Dec 2013 Link to this post

    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.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Dec 2013 Link to this post

    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.
  6. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 17 Dec 2013 Link to this post

    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
  7. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Dec 2013 Link to this post

    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.
  8. Answer
    Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 17 Dec 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017