I'm using latest stable versions of Angular (6.0.9) and PrimeNG (6.0.1). When I try to add child node to selected node programmatically it doesn't show up unless i collapse and then expand selected parent node. First i tried
this.selectedNode.children.push(this.nodeToAdd);
Then I saw in official documentation that if "you manipulate the value such as removing a node, adding a node or changing children of a node, instead of using array methods such as push, splice create a new array reference using a spread operator or similar". So i tried this:
this.selectedNode.children = [...this.selectedNode.children, this.nodeToAdd];
but it results in same behavior. Does anyone facing same issue, or am I doing something wrong? Issue is happening in Chrome, Firefox and Edge
I had the same issue after moving from PrimeNG 5 to 6. The solution from Artem worked, but also caused flashing of the treetable.
I found another solution - just change the reference of root nodes, this will refresh the tree. Add this line after adding / removing nodes:
this.roots = [...this.roots]; // change "roots" to your variable name
I've faced the same issue, spread operator also haven't worked for me, but fortunately I found workaround here (here they trying to refresh prime-ng datatable) It's not direct solution, but it can save you while bug in component (i believe so) isn't fixed.
Here's code from original answer, slightly changed for treetable:
visible: boolean = true;
updateVisibility(): void {
this.visible = false;
setTimeout(() => this.visible = true, 0);
}
<button (click)="updateVisibility()">
<p-treeTable *ngIf="visible"></p-treeTable>
P.S. I use Angular 5, but hope it will help anyway
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With