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

查看:26
本文介绍了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>

Update 从 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: number:当前item在iterable中的索引.
  • first: 布尔值:当项目是可迭代中的第一项时为真.
  • last: 布尔值:当项目是可迭代中的最后一项时为真.
  • even: 布尔值:当项目在可迭代对象中具有偶数索引时为真.
  • odd:布尔值:当项目在可迭代对象中具有奇数索引时为真.
    • 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天全站免登陆