如何像在ngFor中一样在primeng p-table中设置索引变量 [英] how to set index variable in primeng p-table like in ngFor
本文介绍了如何像在ngFor中一样在primeng p-table中设置索引变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮帮我.我想初始化索引变量,如*ngFor="let d of sI.detail;let i=index";
Can any one assist me. I want to initialize index variable like
*ngFor="let d of sI.detail;let i=index"
在我的 p 表中
<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>```
推荐答案
您可以在表中使用 let-rowIndex=rowIndex"
属性.这将为您提供该行的索引.
You can use let-rowIndex="rowIndex"
property in your table. This will give you index of the row.
<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>
希望对您有所帮助!
这篇关于如何像在ngFor中一样在primeng p-table中设置索引变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文