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

Check Children Support (tri-state checkboxes)?

1 Answer 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Basem
Top achievements
Rank 1
Basem asked on 27 Feb 2012, 06:20 AM
On the AJAX RadControls side, there is a property in the TreeView called "CheckChildren" that enables tri-state checkboxes (check mark when all children are checked; shaded box if NOT ALL the children are check marked). Here is the demo of it on the left side: http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/checkboxes/defaultcs.aspx

What is the best way to get the same effect in the MVC TreeView? It does not seem this feature is supported. I am check marking nodes in the data bind, but I was hoping the treeview control would be smart enough to handle the check mark state of the parent based on it's children if "CheckChildren=True".

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 29 Feb 2012, 05:23 PM
Hi Basem,

Yes such functionality is currently not supported. Here are some tips to simulate such behavior:
  1. Subscribe to the OnChecked client event.
  2. If the checkbox in the current item is selected then add the 'checked' attribute to all the children, if not remove the 'checked' attribute.
    function onChecked(e) {
            var currentCheckbox = $(e.item).find(':checkbox:eq(0)');
            var allChildren =$(e.item).find(':checkbox');
            currentCheckbox.is(':checked') ? allChildren.attr('checked', 'checked') : allChildren.removeAttr('checked');
    }
  3. Check if all the siblings are checked mark the parent as check
  4. Check if all the siblings are unchecked mark the parent as unchecked
  5. If 3) or 4) is not true mark the parent as shaded box (apply background image and CSS)

Kind regards,
Petur Subev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
TreeView
Asked by
Basem
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or