Using PrimeNG, I can scroll to a TreeNode:
In html:
<p-tree #mytreeid id="mytree"></p-tree>
In Angular:
@ViewChild("mytree") mytree: Tree;
// selection is the TreeNode you want to scroll into view
scrollToSelectionPrimeNgDataTree(selection, tree, elementIdName) {
if (tree.value !== null) {
let index = tree.value.indexOf(selection);
let ele = document.getElementById(elementIdName).querySelectorAll("p-treenode")[index];
ele.scrollIntoView();
//ele.focus();
}
}
Question: How to make the TreeNode(ie. 'selection') focused? I tried to call the focus() method, but focus() is not the method of the Element.
I found the solution, we only need to set the [(selection)] to the selected node:
<p-tree #mytree id="mytree" [value]="componentGroups" selectionMode="single" [(selection)]="selectedNode">
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