[zTree] Automatic checking of parent?

Forge Component
Published on 3 Oct (3 weeks ago) by Eduardo Luís
18 votes
Published on 3 Oct (3 weeks ago) 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.

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

Hi Eduardo,

I want to keep the child or parent node's checked status independent of selected node. Basically, if I check or uncheck a node it should not affect it's parent node or child node. I have kept the attribute zTreeSettingsCheck.chkBoxType as 'False' but still it's not not working. The parent node is getting greyed out along with checked on selection of any child node. I am using the Lazy Loading Technique as I have thousands of records to load on the tree.

Could you please help me on this.