[zTree] Automatic checking of parent?

[zTree] Automatic checking of parent?

  
Forge Component
(8)
Published on 29 Feb by Eduardo Luís
8 votes
Published on 29 Feb by Eduardo Luís
Is there a way to automatically have the parent be checked or half-checked based on the children's check status? Or do I need to provide for that manually? If I set the parent as unchecked but there's at least one checked child, its checkbox gets greyed but not checked. If I set the parent as checked and not all children are checked, its checkbox gets greyed + checked (and if all children are checked, normally checked). What I'd like is: no children checked, not checked; some (but not all) children checked, grey + checked; all children checked, checked.
Hello,

if you're talking about the way the tree behaves when the user checks/unchecks a node then yes it's possible. You can use the 'chkboxType' config parameter. See the first example on the Checkbox & Radio group (Checkbox Operation).

If you're talking about the initial load then you have to set the node status manually. You can use the 'checked' and 'halfChecked' data parameters. See the 'Checkbox halfCheck Demo' example on the same group.


Hope it helps
Ok, thanks.
I found out that if initially setting the parent's checked to False, then setting it to True in case at least one child is checked, does what I want. I needn't meddle with the halfChecked (i.e., it half checks automatically, unless all children are checked, in which case it checks). Slightly less desirable than automatic checking, but better than needing to make the distinction between halfChecked and checked.
Ok, glad i can help