Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some nodes are not checked #20

Open
Praetorian11 opened this issue Feb 21, 2022 · 2 comments
Open

Some nodes are not checked #20

Praetorian11 opened this issue Feb 21, 2022 · 2 comments

Comments

@Praetorian11
Copy link

Hello,
Strange problems, please see code bellow

`

<title>
</title>
<script src="dist/tree.min.js"></script>
<script> let data = [{"id":1,"text":"Home","checked":true,"children":[{"id":7,"text":"TimeTable","checked":true,"children":[{"id":8,"text":"Staff Att","checked":true,"children":[]}]}]},{"id":2,"text":"Student","checked":true,"children":[]},{"id":3,"text":"Staff","checked":true,"children":[]},{"id":4,"text":"Library","checked":true,"children":[{"id":9,"text":"Book Issue","checked":true,"children":[]},{"id":10,"text":"Book Return","checked":true,"children":[]},{"id":11,"text":"Book Fine","checked":true,"children":[{"id":12,"text":"Fee Payment","checked":true,"children":[]}]}]},{"id":6,"text":"StudentAtt","checked":true,"children":[]}]
let tree = new Tree('.treeContainer', {
    data: [{ id: '-1', text: 'root', children: data }],
    closeDepth: 3,
    loaded: function () {
    },
    onChange: function () {
        console.log(this.values);
    }
})
</script> `

All nodes are checked by initial data, but 2 nodes "Book Issue" and "Book Return" are not checked, very strange.

obrazek
Can you check it, please? Thank you.

@Wonko52
Copy link

Wonko52 commented Mar 9, 2022

That is the logic behind it:

Every "checked: true" is handled like a click on the node.

If you start with a completely unchecked treeview and click on Library, all subnotes are checked. If you also click "Book Issue", it becomes unchecked again.

Same with "Book Fine", but it is checked again when you click on "Fee Payment".

Solution: Set "checked: true" only for the node that should really be selected (e.g. "Fee Payment" and not "Book Fine" or "Library").

But I would guess that this is a bug and not intended...

@THenkeDE
Copy link

THenkeDE commented Oct 17, 2023

only set checked=true on nodes that do not have children on their own because their checked / half checked / not checked status is inherited by the sum of checked children

Inside the Tree.parseTreeData one may add

- if (node.checked ) values.push(node.id);
+ if (node.checked && (!node.children || node.children.length === 0) ) values.push(node.id);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants