ClientSide Unselect Node

4 posts, 0 answers
  1. Neil
    Neil avatar
    50 posts
    Member since:
    Mar 2009

    Posted 01 Apr 2011 Link to this post

    When I select a node in a TreeView, I'd like the ability to unselect it without selecting a different node by clicking the node (to toggle it selected or unselected)

    <telerik:RadTreeView ID="blocks"  ShowLineImages="false" runat="server" OnClientNodeClicked="BlockClicked" MultipleSelect="true">
        <NodeTemplate >
    ......
        </NodeTemplate>
    </telerik:RadTreeView>

    This JavaScript doesn't seem to do what I thought...

    function BlockClicked() {
            var tree = $find("<%= blocks.ClientID %>");
            var node = tree.get_selectedNode();
            if (node.IsSelected == false) {
                alert('Selected');
                node.unselect();
            }
            else {
                alert('Not Selected');
                node.select();
            }
        }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Apr 2011 Link to this post

    Hello,


    You could enable the default checkboxes of RadTreeView and try teh following client code to accomplish your requirement.

    Code:
    function OnClientNodeClicked(sender, args) {
        var node = args.get_node();
        node.set_checked(!node.get_checked());
    }



    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Neil
    Neil avatar
    50 posts
    Member since:
    Mar 2009

    Posted 04 Apr 2011 Link to this post

    Any way to  do this without using the checkboxes?
  5. Neil
    Neil avatar
    50 posts
    Member since:
    Mar 2009

    Posted 04 Apr 2011 Link to this post

    Seems the "OnClientNodeClicking" event did the trick:

    <telerik:RadTreeView ID="Tree" ShowLineImages="false" runat="server" OnClientNodeClicking="NodeClicking"
            MultipleSelect="true">
            <NodeTemplate>
                ......
            </NodeTemplate>
        </telerik:RadTreeView>


    function NodeClicking(sender, eventArgs) {
            var node = eventArgs.get_node();
            var isSelected = node.get_selected();
     
            if (isSelected) {
                node.set_selected(false);
            }
            else {
                node.set_selected(true);
            }
     
            eventArgs.set_cancel(true);
        }

Back to Top