This is a migrated thread and some comments may be shown as answers.

RadTreeView checkboxes with tri-state behaviour

7 Answers 155 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
S
Top achievements
Rank 1
S asked on 21 Mar 2012, 03:43 PM
Hi there @Telerik forums,

I have the following problem with the RadTreeView checkboxes:
I do have tree-structure in the database which gets presented with a RadTreeView control - a tree structure with nodes and leaves. The special situation there is the fact a node can be checked, but none of its leaves needs to be checked. You could imagine a virtual structure of access rights where a node is some major right and a leaf of this node is a right which might or might not be set. If it is set the major right must be set, but if none of the minor rights (the leaves) has been set, the major right should remain set until explicitely unset...

Well the Telerik guys say that in the RadTreeView this behaviour is not possible as the logic of the controls does not allow a node to be checked without at least one checked leaf. This post mentiones it...

My RadTreeView declaration:
<tr id="TrMenuRights" runat="server">
            <td width="30%" valign="top"><asp:Label ID="LabelMenuRights" runat="server" Text="Menürechte"/></td>
            <td style="border: 1px solid">
                <telerik:RadTreeView ID="RadTreeViewMenu" runat="server" TriStateCheckBoxes="true" OnClientNodeChecked="OnTreeNodeCheck" Height="200px" Width="100%" /> 
            </td>
</tr>

My question is: are there possibilities to achieve the requested behaviour with the RadTreeView control (or possibly with other Telerik control?)
Please consider this post as a shout of a desperated programer as my application needs this behaviour (customer's requirement!)...
Many thanks in advance for your attention.

Kind regards,
S.

7 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 26 Mar 2012, 09:40 AM
Hello S,

 
The tri-state checkbox behavior in RadTreeView is implemented according to the standards. Since the functionality you want to achieve is different I will recommend you not to use "tri-state" but to use the client object of RadTreeNode and implement your own logic of setting the check state of the node according your needs in onClientNodeClicking event.

Hope this information will be helpful.
 

Regards,
Plamen Zdravkov
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.
0
S
Top achievements
Rank 1
answered on 02 Apr 2012, 03:12 PM
Hi Mr. Zdravkov,

I was trying to implement the requested functionality using the "tri-state" mode set to false, but unfortunately there is some special behaviour, which prevents me from success...
If the tri-state mode has been set off, then the RadTreeView (on the client side) control does not support the property "_children". This way I'm unable to implement the requested logic.
Could you please give me some simple code where you show me how to traverse through the parents and children of a node, when the RadTreeView has the "normal" checkbox state?

My simple goal would be (with "checkbox" I mean a node with its checkbox):
1. Each children's checkbox uncheck does not automatically lead to parent's checkbox unchek.
2. Each checkbox uncheck will automatically uncheck all checkboxes on all direct and indirect children.
3. Each checkbox check will verfy that the parent checkboxes (direct and indirect in the node's chain) has a checkmark.

Please advise me how to achive this functionality without to use the tri-state mode.
Many thanks in advance.

Kind regards,
S.
0
Plamen
Telerik team
answered on 05 Apr 2012, 09:19 AM
Hi S,

 
You can use the onClientNodeChecked event and set _checked state of the child nodes as in the following code:

function OnClientNodeChecked(sender, args) {
           var node = args.get_node();
 
           for (var i = 0; i < node.get_allNodes().length; i++) {
               var childNode = node.get_allNodes()[i];
               if (node.get_checked()) {
                   childNode.set_checked(true);
               }
               else {
                   childNode.set_checked(false);
               }
           }
       }

Hope this will be helpful.

Regards,
Plamen Zdravkov
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.
0
S
Top achievements
Rank 1
answered on 05 Apr 2012, 11:36 AM
Thank you Mr. Zdravkov,

I was not aware of the method get_allNodes and didn't knew that this will return all child nodes of a node. Also the "property" _properties and its subproperty _data were needed to push my efforts to the successful end...

Please consider this thread closed.

Kind regards,
S!
0
mayur
Top achievements
Rank 1
answered on 16 Apr 2015, 01:55 AM

hello sir ,

​i have same problem that if all child node is checked then parent node must be checked but its not coming when i set tristate property false.

please help me in that ,how to achieve this functionality

0
Plamen
Telerik team
answered on 17 Apr 2015, 07:26 AM
Hello,

This is a custom scenario that may be achieved by using the client API of RadTreeView as for example in the code below:
function OnClientNodeChecked(sender, args) {
 
           var node = args.get_node();
           var parentNodes = node.get_parent().get_nodes();
          
           if (node.get_checked()) {
               var checkFlag = true;
               for (var i = 0; i < parentNodes.get_count(); i++) {
                   if (!parentNodes.getNode(i).get_checked()) {
                       checkFlag = false;
                   }
               }
 
               if (checkFlag) {
                   node.get_parent().set_checked(true);
               }
           }
       }
 
 
   </script>
       <telerik:RadTreeView runat="server" CheckBoxes="true" OnClientNodeChecked="OnClientNodeChecked">

Hope this information will be helpful.


Regards,
Plamen
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
mayur
Top achievements
Rank 1
answered on 18 Apr 2015, 03:26 AM
Thanks plamen I am looking for the same solution.
Tags
TreeView
Asked by
S
Top achievements
Rank 1
Answers by
Plamen
Telerik team
S
Top achievements
Rank 1
mayur
Top achievements
Rank 1
Share this question
or