Home > other >  Antd Tree, : how to Disable checking child by default
Antd Tree, : how to Disable checking child by default

Time:03-06

I working on a react project using Antd and I want to be able to disable cheking childs of my Tree component, so I can check only parent.Sample Results

NOTES:

  1. The elements showing as checked are clicked manually.
  2. There is no check option for nodes 0-0-0, 0-0-1, 0-0-2, 0-1-0-0, 0-1-0-1, 0-1-0-2 - which is the expected objective defined in the question under To this

EDITED:

On perusing Possible actually-desired objective

(A tree where leaf nodes are uncheckable)

This may be achieved by a recursive method - something like this:

Changes to code

(Changes are present in: Lines 100 to 106. And line 118.)

EDITED - 2 Update based on comments below. In order to identify the children for any given parent/key, something like the below may be useful:

findKey and getChildren

Two methods are here. One is findKey which is recursive and gets the object which has a particular key (say 0-0-1). The other is to check if the object with the key has any children and if yes, return the children array.

  • Related