angularprimeng

PrimeNG TreeTable cannot get Row index


Trying to use rowIndex inside TreeTable. With DataTable rowIndex works fine, but with TreeTable rowIndex is undefined.

<p-treeTable [value]="files1">
  <p-header>Basic</p-header>
  <p-column header="ID">
    <ng-template let-rowIndexValue="rowIndex" pTemplate="body">
      <p class="rw-center-align">{{rowIndexValue}}</p>
    </ng-template>
  </p-column>
  <p-column field="name" header="Name"></p-column>
  <p-column field="size" header="Size"></p-column>
  <p-column field="type" header="Type"></p-column>
  <p-column header="Actions">
    <ng-template let-rowIndexValue="rowIndex" pTemplate="body">
      <button pButton label="Add child" (click)="addChild(rowIndex)"></button>
    </ng-template>
  </p-column>
</p-treeTable>

Here in addChild() method I'm getting rowIndexValue as undefined, and ID column is empty.


Solution

  • From the doc :

    rowIndex well exists for DataTable but not for TreeTable