Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Node Index on PrimeNG Tree Nodes

Since p-tree from PrimeNG does not have way of using rowIndex. How do I display/get the Index of nodes each node using ng-template.

Is there any workaroud?

like image 899
Kishor Prakash Avatar asked Nov 30 '25 19:11

Kishor Prakash


1 Answers

Within the ng-template, you can call the indexOf() method on your collection and pass the current item as the argument. This will either return the index of the first instance of that item or -1 if that item isn't found. You can display the result of that call within curly braces in the HTML.

<p-tree [value]="items">
    <ng-template let-item pTemplate="default">
        <span>{{ items.indexOf(item) }}</span>
    </ng-template>
</p-tree>
like image 107
mdwatson988 Avatar answered Dec 02 '25 09:12

mdwatson988



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!