<p-dataTable [value]="services" [paginator]="true" expandableRows="true" rowExpandMode="single">
...</p-dataTable>
存在一些像这样的
<ng-template let-col let-period="rowData" let-ri="rowIndex" pTemplate="body">...</ng-template>
for DataTable
答案 0 :(得分:6)
在扩展行的ng-template中使用以下代码
<ng-template let-i="rowIndex">
<button (click)="expand(i)"> expand </button>
</ng-template>
在展开期间点击的按钮中,使用以下代码获取rowindex
expand(i){
//... your logic to expand the row...
this.expandedRowIndex = i;
}
<p-dataTable [value]="services" [paginator]="true" expandableRows="true" rowExpandMode="single" (onRowExpand)="onRowExpand($event)">
更新1:
当您单击要展开的整行时。您可以使用onRowExpand
的{{1}}属性来实现此目的。
<p-datatable>
扩展行时会触发此方法
<强> LIVE DEMO 强>
答案 1 :(得分:3)
<ng-template let-i="rowIndex" let-line pTemplate="rowexpansion">
rowIndex
现在可能已添加到rowExpansion
,适用于我的最新版本
答案 2 :(得分:1)
您可以使用它:
<ng-template pTemplate="body" let-record="$implicit" let-rowIndex="rowIndex">
<tr [pSelectableRow]="record">
<td>
{{rowIndex + 1}}