dipson88 / treeselectjs

Treeselect on vanilla JS
MIT License
82 stars 15 forks source link

Select all tree when parent is selected. #73

Open massiws opened 1 year ago

massiws commented 1 year ago

In the default props config, when selecting the parent item ONLY parent is selected: default_props

Version 0.9.0 allow nodes to be selected independently, but this require to click each node, hard work if there are many children.

It would be very useful having an option (something like allTree) to allow add parent AND all its children when the parent is selected.

Thank you.

dotgourav commented 1 year ago

After the independent node selection feature, this becomes rather important. Although, how would you include this in the UI?

dipson88 commented 1 year ago

@massiws and @dotgourav, I can implement the next behavior: I will show all nodes which have a check icon. So if we click England -> England, London, Chelsea, West End, Brighton. if we use a situation like on screenshot -> London, Chelsea, West End. But if I click London off, we will unclick all children, and the input will be empty. It looks strange or not? What do you think? Because I didn't see a behavior like this before. I see only grouped: true/false behavior, and It was implemented. What about grouped prop - Show groups in the input and group leafs if all groups selected. You can set this prop to false. And you will see only children without groups name. Can it work for you or not?

massiws commented 1 year ago

Thank you @dipson88!

Thinking treeselectjs in a search bar maybe could be a real scenario:

The grouped option (in my opinion) has a different funcionality.

Hope this make sense.

massiws commented 1 year ago

@dipson88 any updates?

dipson88 commented 1 year ago

@massiws, sorry no updates. Your request make sense, but I faced problems, the code became more hard-readable. The problem is related to the input/list communication: when selected 3 nodes (1 parent and 2 children), I unselect the child, but my algorithm checked that parent was still selected, and he runs through the list and checked all children and set partial checked or checked for his parents. I guess if implement this feature, I need to rewrite the whole algorithm, but It is not a nice decision, or use a hard-readable code, and in the future, it will be hard supported. Looks like it is a huge task with refactoring, and maybe I need to change the group and isGroupedValue props behavior. isIndependentNodes prop was possible to implement because I just don't use the child/parent algorithm for this behavior. In the future, I'm going to resolve this task, but now it looks like a too hard to implement.