HERE'S A STACKBLITZ FOR THIS PROBLEM:
https://dynamic-ng-grid.stackblitz.io
I have to access the rowIndex or row data where I have used ngFor, I tried using rowIndex and went through the docs but unable to find out how it could work. Any help would be great thank. Let me know if any further information is required. Here's the code:
<ngx-datatable
style="height: 450px; cursor: pointer;"
class="material"
[rows]="rows"
[rowHeight]="70"
[footerHeight]="50"
columnMode="force"
[scrollbarV]="true"
[scrollbarH]="true">
<!-- months col -->
<ngx-datatable-column
*ngFor="let month of getMonths(rows, rowIndex)" // THIS IS THE PLACE WHERE I HAVE TO ACCESS THE ROWINDEX OR ROW BUT UNABLE TO ACCESS IT
[name]="month.name"
[width]="465">
<ng-template let-value="value" let-row="row" let-rowIndex="rowIndex" ngx-datatable-cell-template>
<span *ngIf="!month.detail; then avgTemp; else ratingTemp;"></span>
<!-- average score -->
<ng-template #avgTemp>{{ month.value | json }} MV</ng-template>
<!-- monthly rating -->
<ng-template #ratingTemp>
<span *ngIf="month.detail.rating.isNA === 'Y'; then isNaTemp; else notNaTemp"></span>
<!-- N/A -->
<ng-template #isNaTemp>N/A</ng-template>
<!-- Non-N/A -->
<ng-template #notNaTemp>
<span *ngIf="month.detail.rating.hrRating !== null; then hrRatTemp; else otherRatTemp"></span>
<!-- Hr Rating -->
<ng-template #hrRatTemp>{{ month.detail.rating.hrRating }} HR</ng-template>
<ng-template #otherRatTemp>
<span *ngIf="month.detail.rating.lmRating !== null; then lmRatTemp; else otherRatTemp"></span>
<!-- Lm Rating -->
<ng-template #lmRatTemp>{{ month.detail.rating.lmRating }} LM</ng-template>
<ng-template #otherRatTemp>
<span *ngIf="month.detail.rating.empRating !== null; then empRatTemp; else zeroTemp"></span>
<!-- Emp Rating -->
<!-- <ng-template #empRatTemp>{{ month.detail.rating.empRating }} Emp</ng-template> -->
<ng-template #empRatTemp>{{ row.months | json }} Emp</ng-template>
<ng-template #zeroTemp>
<span *ngIf="(rowIndex + 1) != rows.length">0</span>
</ng-template>
</ng-template>
</ng-template>
</ng-template> <!-- Non-N/A -->
</ng-template> <!-- monthly rating -->
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
Base on your stackblitz:
app.component.ts
@ViewChild(DatatableComponent) table: DatatableComponent;
public getRowIndex(row: any): number {
return this.table.bodyComponent.getRowIndex(row); // row being data object passed into the template
}
app.component.html
...
<ngx-datatable .... #table>
<ngx-datatable-column>
{{ getRowIndex(row) }}
</ngx-datatable-column>
...
I hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With