typescript Primeng 如何获取行的rowIndex 展开?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43790050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Primeng How get rowIndex of row expanded?
提问by alehn96
<p-dataTable [value]="services" [paginator]="true" expandableRows="true" rowExpandMode="single">
...</p-dataTable>
exists some like this
存在一些这样的
<ng-template let-col let-period="rowData" let-ri="rowIndex" pTemplate="body">...</ng-template>
for DataTable
用于数据表
回答by Aravind
In your ng-template for the expansion of row use the below code
在用于行扩展的 ng-template 中,使用以下代码
<ng-template let-i="rowIndex">
<button (click)="expand(i)"> expand </button>
</ng-template>
In the button that is clicked during expansion use the below code to get the 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)">
Update 1:
As you are clicking the entire row to be expanded. You can use the onRowExpand
property of the <p-datatable>
to achieve this.
更新 1:当您单击要展开的整行时。您可以使用 的onRowExpand
属性<p-datatable>
来实现这一点。
onRowExpand(cc){
console.log(cc)
//logs the entire object which is clicked
}
This method is triggered when the row is expanded
该方法在行展开时触发
回答by sabithpocker
<ng-template let-i="rowIndex" let-line pTemplate="rowexpansion">
rowIndex
is probably added to rowExpansion
now, works for me in latest version
rowIndex
可能已添加到rowExpansion
现在,在最新版本中对我有用
回答by Abdus Salam Azad
You can use it:
你可以使用它:
<ng-template pTemplate="body" let-record="$implicit" let-rowIndex="rowIndex">
<tr [pSelectableRow]="record">
<td>
{{rowIndex + 1}}