如何在 primeng p-table 中设置索引变量,就像在 ngFor 中一样

how to set index variable in primeng p-table like in ngFor

谁能帮帮我。我想像这样初始化索引变量 *ngFor="let d of sI.detail;let i=index"

在我的p-table

<ng-template pTemplate="body" let-rowData >
      <tr class="text-center info">
        <td>{{ totalHeader }} </td>
        <td>
          <span>
            {{ rowData?.totalUnits }}
          </span>
          <span>
            ({{ rowData?.totalSale }})
          </span>
          <span *ngIf="rowData.totalUnits && rowData.totalSale">
            /{{ (rowData.totalUnits/rowData.totalSale) | percent:'1.2-2' }}
          </span>
        </td>
      </tr>
    </ng-template>```

您可以在 table 中使用 let-rowIndex="rowIndex" 属性。这将为您提供该行的索引。

<ng-template pTemplate="body" let-rowData let-rowIndex="rowIndex">
      <tr class="text-center info">
        <td>{{ totalHeader }} </td>
        <td>
          <span>
            {{ rowData?.totalUnits }} {{rowIndex + 1}} // here is value to use
          </span>
          <span>
            ({{ rowData?.totalSale }})
          </span>
          <span *ngIf="rowData.totalUnits && rowData.totalSale">
            /{{ (rowData.totalUnits/rowData.totalSale) | percent:'1.2-2' }}
          </span>
        </td>
      </tr>
    </ng-template>

希望对您有所帮助!