Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1840
Only checkboxes on child nodes
posted

Hello,

i use the WebDataTree with a WebHierarchicalDatasource and CheckBoxMode 'BiState'. But i don't want the checkboxes on the parent nodes (only the leafs in the tree are 'checkable'). Is there any simple way to change the default behavior (may be a flag or a property 'no_parent_checkboxes') ?

Parents
  • 33839
    Verified Answer
    posted

    Hi Page,

    As Nikola said, this is not built in, but you can get around it with some client code in the initialize event.  What you will do is hide the checkboxes you do not wish to show in the initialize event.  You said that you did not want parent nodes to be checkable.  I do not know whether you mean root nodes or in general, so I'll give some generic code.

    function HideCheckbox(node)
            {
                var childCount = node.get_childrenCount();
                if (childCount != 0)
                {
                    var checkbox = node._get_checkBox();
                    var checkboxEl = node._get_checkBox().get_element();
                    if (!checkboxEl && node._get_expandCollapseElement()){
                        checkboxEl = node._get_expandCollapseElement().nextSibling;
                    }
                    if (checkboxEl)
                    {
                        checkboxEl.style.display = "none";
                    }
                }
                for (var x = 0; x < childCount; ++x)
                {
                    var child = node.get_childNode(x);
                    HideCheckbox(child);
                }
            }
       
            function init(tree, args) {
                var root = tree.getNode(0);
                while (root != null) {
                    HideCheckbox(root);
                    root = root.get_nextNode();
                }
            }

    This code will hide checkbox in all nodes that do have children.  If you want to just do the root nodes, move the code where the checkbox is hidden into the while loop of init and don't worry about child nodes.  I checked this code in IE 8, FF, Safari, Opera, and Chrome. One thing to note is that the checkboxes that are hidden could still be automatically checked if you do not set EnableAutoChecking (available in 9.2) to false.  If you need this true or have 9.1, and you don't want nodes without checkbox in the checked nodes collection, I suggest handling CheckBoxSelectionChanged client event and uncheck those nodes in that event if needed.  Let me know if you need help.

    Hopefully this will get you by in the meantime.  But I suggest submitting that feature request.

    regards,
    David Young

     

Reply Children
No Data