Disable Parent Node Clicks

6 posts, 0 answers
  1. Tanya
    Tanya avatar
    4 posts
    Member since:
    Apr 2012

    Posted 16 Apr 2013 Link to this post

    hi!

    i currently have checkboxes only allowed on child nodes, but when the user clicks on the parent name it automatically checks all child nodes. how can i set the tree, so that the user cannot click on the parent node names, or is able to click, but i don't want the child node checkboxes to all get checked automatically.

    the user needs to check the boxes manually one by one.

    hope i explained it right.


    <telerik:RadTreeView ID="rtvLabs" runat="server" CheckBoxes="true" Skin="Outlook"
                          TriStateCheckBoxes="true" CheckChildNodes="false" SingleExpandPath="true"
                          OnClientNodeChecked="ClientNodeChecked" OnClientNodeClicked="ClientNodeClicked">
                      </telerik:RadTreeView>

    in the back end i am setting the nodes as checkable=false; if they are a parent  which gets rid of the checkbox itself, 
    , but i guess that isn't enough? how do i prevent the user from selecting ALL child nodes by simply clicking on the parent name?
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 19 Apr 2013 Link to this post

    Hello Tanya,

    You could prevent checking for all child nodes by handling OnClientNodeClicking event and canceling the click for the root nodes:
    function OnClientNodeClicking(sender, args) {
        //Chech if clicked node does not have child items
        if (args.get_node().get_level() == 0 || args.get_node().get_lastChild() != null) {
            args.set_cancel(true);
        }
    }

    All the best,
    Hristo Valyavicharski
    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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amjad
    Amjad avatar
    36 posts
    Member since:
    Dec 2010

    Posted 28 Jan 2014 in reply to Hristo Valyavicharski Link to this post

    Hi,
    what about if I want to remove the checkbox itself from the parent nodes?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2014 in reply to Amjad Link to this post

    Hi Amjad,

    Please try to set the Checkable property to false to remove the checkbox from the 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_checkable(false);
            }
        }
    </script>

    Thanks,
    Shinu.
  6. Amjad
    Amjad avatar
    36 posts
    Member since:
    Dec 2010

    Posted 28 Jan 2014 in reply to Shinu Link to this post

    Thanks Shinu,

    it worked great, also am looking for how make the parent node unselect able or highlighted.

    Any ideas?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2014 in reply to Amjad Link to this post

    Hi Amjad,

    Please try to set the set_selected() property of root node to false on OnClientNodeClicked event as follows.

    JavaScript:
    <script type="text/javascript">
        function OnClientNodeClicked1(sender, args) {
            if (args.get_node()._hasChildren() == true)
                args.get_node().set_selected(false)
        }
    </script>

    Thanks,
    Shinu.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017