-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Tree: If user filter tree nodes and then lazy load new children (with .key prop) - nodeClick event is not emitted #14723
Comments
Hi @cetincakiroglu |
Ping me if you have some reproduce questions, we can zoom if needed. [email protected] |
Hi, Thank you very much for reporting the issue. The Tree component uses the key property to establish a context between child and parent nodes, and as you have seen in the source code, the key is used to search for the selected node. If the key is not found, the existing node is returned, causing the
Here, instead of this.value, as you also mentioned, it should be this.filteredNodes. Making this change and fixing the demo makes the example work without any issues. After today's release, you can simply copy-past and try the updated demo code above:
|
Describe the bug
Primeng tree - seems like all version affected
Reproduce steps:
Root cause:
treeRef.value is not refering same node objects as treeRef.filteredNodes anymore after filtering (https://github.com/primefaces/primeng/blob/16.9.1/src/app/components/tree/tree.ts#L1617)
And since if we have .key prop on node objects - in onNodeClick event Node is checked for existence on treeRef.value object and not in treeRef.filteredNodes
https://github.com/primefaces/primeng/blob/16.9.1/src/app/components/tree/tree.ts#L1247
So newly added nodes after filtering dot not emit onNodeClick event.
Solution:
If add node.children after filtering add them to respective node in treeRef.value as well
Maybe not create node copy for filteredNodes but use original node object?
Reproduce repo: https://codesandbox.io/p/devbox/primeng-tree-lazy-demo-forked-hvm6ls
Environment
https://codesandbox.io/p/devbox/primeng-tree-lazy-demo-forked-hvm6ls
Reproducer
No response
Angular version
16.2.0
PrimeNG version
16.9.4-lts
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
v20.9.0
Browser(s)
Chrome
Steps to reproduce the behavior
Reproduce steps:
Expected behavior
User can click on newly lazy loaded nodes even after applying filter on tree
The text was updated successfully, but these errors were encountered: