RadTreeNode cannot set unchecked from client side

2 posts, 0 answers
  1. Dev
    Dev avatar
    28 posts
    Member since:
    Jan 2011

    Posted 01 Feb 2013 Link to this post

    Hi !

    I have a RadTreeview to which I have set properties CheckBoxes="true"  and OnClientNodeChecking="ClientNodeChecking".

    Now, at server-side RadTreeViewMain_NodeDataBound() event I am setting e.Node.Checkable = false; for all nodes.

    Then I am checking e.Node.Category from database for each node and if node is of "Option" category, then I am setting e.Node.Checkable = true;

    at client-side I have defined a javascript function which is used to uncheck all of the child nodes of the node on unchecking itself.

    Surprisingly, it works fine fist time when I check the node and uncheck the same. But after that if I click the same node to make it checked, it shows it is already checked, while in UI it is not checked.

    Javascript functions are as below :

    function ClientNodeChecking(sender, eventArgs) {
        var node = eventArgs.get_node();
        var parent = node.get_parent();
        var t = node.get_treeView();
        var preventCheck = false;
        var isMultiSelect = parent.get_attributes().getAttribute("multiSelect");
        var allNodes = parent.get_allNodes();
        var value = node.get_value();
        var checkstate = node.get_checkState();
        var level = node.get_level();
        var errormessage = "";
     
        if (checkstate == 1) {
            t.trackChanges();
            node.uncheck();
            getAllChildUnchecked(node);
            t.commitChanges();
            return;
        }
     
        if (level > 2) {
            var grandParent = parent.get_parent();
            var grandParentCategory = grandParent.get_category();
     
            if (grandParentCategory == "Option" && !grandParent.get_checked()) {
     
                // you can add simple alert message here..
                //errormessage = "The parent node is not checked.";
                //openDialogPreventChecked(errormessage);
                eventArgs.set_cancel(true);
                return;
            }
        }
        if (allNodes.length > 0) {
            for (var i = 0; i < allNodes.length; i++) {
                var childnode = allNodes[i];
                var childvalue = childnode.get_value();
                if (childnode.get_checked() && isMultiSelect == "false" && value != childvalue) {
                    preventCheck = true;
                    break;
                }
            }
        }
        if (preventCheck) {
            // you can add simple alert message here..
            eventArgs.set_cancel(true);
            //errormessage = "This is not multi-select type of question";
            //openDialogPreventChecked(errormessage);
        }
    }
     
    function getAllChildUnchecked(node) {
        var childNodes = node.get_allNodes();
        if (childNodes.length > 0) {
            for (var i = 0; i < childNodes.length; i++) {
                var childnode = childNodes[i];
                childnode.uncheck();
                getAllChildUnchecked(childnode);
            }
        }
    }


    Kindly provide me some efficient solution. Awaiting for your valuable response.

    Thanks,
    Dev
  2. Dev
    Dev avatar
    28 posts
    Member since:
    Jan 2011

    Posted 06 Feb 2013 Link to this post

    Resolved my self :

    function ClientNodeChecking(sender, eventArgs) {
        var node = eventArgs.get_node();
        var parent = node.get_parent();
        var t = node.get_treeView();
        var isMultiselect = node.get_attributes().getAttribute("multiSelect");
        var siblingNodes = parent.get_allNodes();
        var isSiblingChecked = false;
        var level = node.get_level();
        if (!node.get_checked()) {
            if (level > 2) {
                var grandParent = parent.get_parent();
                if (!grandParent.get_checked()) {
                    eventArgs.set_cancel(true);
                    errormessage = "Parent node is not checked";
                    openDialogPreventChecked(errormessage);
                    return;
                }
            }
            if (siblingNodes.length > 0) {
                for (var i = 0; i < siblingNodes.length; i++) {
                    var siblingNode = siblingNodes[i];
                    if (siblingNode.get_checked()) {
                        isSiblingChecked = true;
                        break;
                    }
                }
            }
            // Check whether the node if of multiselect type
            if (isMultiselect == "false" && isSiblingChecked) {
                eventArgs.set_cancel(true);
                errormessage = "This is not multi-select type of question";
                openDialogPreventChecked(errormessage);
                return;
            }
        }
    }

    function ClientNodeChecked(sender, eventArgs) {
        var node = eventArgs.get_node();
        var t = node.get_treeView();
        t.trackChanges();
        getAllChildUnchecked(node);
        t.commitChanges();
    }

    function getAllChildUnchecked(node) {
        var childNodes = node.get_allNodes();
        if (childNodes.length > 0) {
            for (var i = 0; i < childNodes.length; i++) {
                var childnode = childNodes[i];
                childnode.uncheck();
                getAllChildUnchecked(childnode);
            }
        }
    }

    P.S. Telerik should update this editor to post question and answer. I am tired of making code blocks readable so just have posted answer without code block. Check out with stackoverflow,.com.

    Thank you,
    Dev
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top