I'm submitting a
[x] bug report
Current behavior
The selected node is incorrect when using filtering option.
It seems that the selectedNode is set on the first parent node found in tree, when using filtering
Expected behavior
Selected node should reflect the real selection
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/github-xz82dx
If filter input is left blank everything is fine.
What is the motivation / use case for changing the behavior?
Behavior is not consistent
Please tell us about your environment:
I guess the problem comes from this code https://github.com/primefaces/primeng/blob/master/src/app/components/tree/tree.ts#L638 :
if (this.hasFilteredNodes()) {
node = this.getNodeWithKey(node.key, this.value);
If think it should be this.filteredNodes instead of this.value in order to use the filteredTree and not the complete tree.
Hey, @tinysquare I am having the same problem and found out that you need to have "key" property on your nodes. Just set key and everything is gonna work.
Thanks, it works with key property set.
Anyway I think it's counterintuitive and at least documentation should mention that key is mandatory when using filtering. Morevover, the demo data doesnt have this key property so I dont know how they get it to work on showcase.
I noticed a link to https://github.com/primefaces/primeng/issues/7237#issue-409791407 (which is confusing because it says "If users have filter and checkbox selection features on Tree, they have to use 'key'" which is incorrect because I'm using single selection and it's still required) on showcase page, but it should be more obvious and explained in "Filtering" section, not on unnoticeable "_more_" link imo.
Unable to replicate with PrimeNG 9.0.5, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.
Most helpful comment
Hey, @tinysquare I am having the same problem and found out that you need to have "key" property on your nodes. Just set key and everything is gonna work.