RadTreeView checkboxes with tri-state behaviour

8 posts, 0 answers
  1. S
    S avatar
    16 posts
    Member since:
    Sep 2010

    Posted 21 Mar 2012 Link to this post

    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.
  2. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 26 Mar 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. S
    S avatar
    16 posts
    Member since:
    Sep 2010

    Posted 02 Apr 2012 Link to this post

    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.
  5. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 05 Apr 2012 Link to this post

    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.
  6. S
    S avatar
    16 posts
    Member since:
    Sep 2010

    Posted 05 Apr 2012 Link to this post

    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!
  7. mayur
    mayur avatar
    6 posts
    Member since:
    Mar 2015

    Posted 15 Apr 2015 in reply to Plamen Link to this post

    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

  8. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 17 Apr 2015 Link to this post

    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.

     
  9. mayur
    mayur avatar
    6 posts
    Member since:
    Mar 2015

    Posted 17 Apr 2015 in reply to Plamen Link to this post

    Thanks plamen I am looking for the same solution.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017