【发布时间】:2019-03-25 07:41:04
【问题描述】:
这里有一个针对这个问题的 StackblITZ:
https://dynamic-ng-grid.stackblitz.io
我必须访问我使用过 ngFor 的 rowIndex 或行数据,我尝试使用 rowIndex 并浏览了文档,但无法找出它是如何工作的。任何帮助都会非常感谢。让我知道是否需要任何进一步的信息。代码如下:
<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>
【问题讨论】:
-
您还面临这个问题吗?只是为了理解您的问题,您究竟需要在哪里访问
rowIndex? -
@wentjun 感谢您与我们联系。是的,我仍然有这个问题。我需要在 ngx-datatable-column 中使用 ngFor 的地方访问它。您也可以在代码中看到,我已将其作为注释。
-
而您的
getMonths()方法无法读取rowIndex? -
是的,我无法在方法中发送 rowIndex。它显示未定义
-
您可以使用数组的索引(数组将从getMonths返回)到ngfor。循环进入数组时会有一个索引!!!
标签: angular ngx-datatable