If you want to expand a row in your ng-template, use the code snippet below:
<ng-template let-i="rowIndex">
<button (click)="expand(i)"> expand </button>
</ng-template>
To retrieve the rowindex when the button is clicked during expansion, implement the following logic:
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:
To expand the entire row with a click, use the onRowExpand
property of the <p-datatable>
.
onRowExpand(cc){
console.log(cc)
//logs the entire object which is clicked
}
This method is triggered when the row is expanded.
https://i.sstatic.net/FcCYj.png
Check out the LIVE DEMO here