Angular Material-获取数据表中行的索引 [英] Angular Material - Getting index of row in data table

查看:382
本文介绍了Angular Material-获取数据表中行的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular Material 中的MatTable组件制作动态数据桌子.

I am using the MatTable component from Angular Material to make a dynamic data table.

我需要获取一行的当前位置.我可以轻松获得用户单击的行,但无法知道其在列表中的当前位置(取决于排序/过滤/分页).

I need to get the current position of a row. I can easily get the row on which the user clicked but I am unable to know its current position in the list (which depends on sort/filtering/pagination).

有什么主意吗?

推荐答案

在您的mat-cell中,您可以获得如下所示的*ngFor索引

in your mat-cell you can get index like *ngFor as below

<mat-cell *matCellDef="let element;let i = index;">
        {{ i }}
</mat-cell>

Angular 5中的

更新也使用index as i

Update from Angular 5 use also index as i

<ng-container matColumnDef="rowIndex">
  <th mat-header-cell *matHeaderCellDef> Index </th>
  <td mat-cell *matCellDef="let element;index as i;"> {{ i }} </td>
</ng-container>

  • index:数字:当前项目在可迭代对象中的索引.
  • first:布尔值:当该项是可迭代项中的第一项时为true.
  • last:布尔值:当该项是迭代器中的最后一项时为true.
  • even:布尔值:当该项在可迭代项中具有偶数索引时为true.
  • odd:布尔值:当该项在可迭代项中具有奇数索引时为true.
    • index: number: The index of the current item in the iterable.
    • first: boolean: True when the item is the first item in the iterable.
    • last: boolean: True when the item is the last item in the iterable.
    • even: boolean: True when the item has an even index in the iterable.
    • odd: boolean: True when the item has an odd index in the iterable.
    • 这篇关于Angular Material-获取数据表中行的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆