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') ?
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
I actually just figured it out. Sorry, no need to reply.
This was very helpful for me, although I need to hide all child checkboxes and show only the root node checkboxes. I am not well versed in javascript and tried to play around with it with no luck. Can you point me in the right direction? Thanks! Dale
Hi,
I have tried to get this to work in vb.net and no luck yet. Is this for a WebDataTree? I do not see some of the functions for it like "node._get_checkBox().get_element();" . Do you have a vb example? Thanks.
Hello David,
thank's for your fast answer and sory for my time delay to answer. Your code exactly solve my problem and work fine. From a performance view, i don't like to catch the Initialize-Event; but it seems to be the right place to change the display style.
Some questions to your code:
Do i need the variable 'checkbox' ? It's never used.
Is the recursive code faster then an iterative version ( may be in a reverse fashion; i traverse the tree with no checkboxes, if the actual node got a childCount of 0, this is a leaf, so set the checkbox. If not go to the next node.)?
Is there a way to use Node-Templating (but how to trigger a node and a leaf)?
Again, thank's for your solution
regards,
Patric