CDK数据表或Material2数据表是否有索引属性? [英] Is there an index property with CDK data table or Material2 data table?

查看:22
本文介绍了CDK数据表或Material2数据表是否有索引属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了 Angular2 Material Design 数据表,它很棒.我想知道是否有任何方法可以获得索引号或行号?类似 row.index 的东西?我在 CDK 数据表文档 中注意到它提到该指令也导出相同的属性为 ngFor (index, even,odd, first, last)" 但没有任何示例如何获取索引.

I am using the Angular2 Material Design data table in my application and it's awesome. I was wondering if there is any way to get the index number or row number? Something like row.index? I noticed in the CDK data table documentation that it mentions that "The directive also exports the same properties as ngFor (index, even, odd, first, last)" but does not have any examples how to get the index.

非常感谢任何帮助或指导.谢谢!

Any help or guidance is greatly appreciated. Thanks!

推荐答案

可以像*ngFor一样获取行索引,在里面添加let i = index

You can get the row index the same way like *ngFor, add let i = index within the <md-row>

<md-row *cdkRowDef="let row; columns: displayedColumns; let i = index; let isOdd = odd; let isEven = even; let isLast = last" 
         [ngClass]="{'highlight': selectedRowIndex == row.id}"
         (click)="highlight(row, i, isOdd, isEven, isLast)">
</md-row>

ts:

highlight(row, index, oddFlag, evenFlag, lastFlag){
    alert("index:" + index + " odd: " + oddFlag + " even: " + evenFlag + " last: " + lastFlag);
    this.selectedRowIndex = row.id;
}

Plunker 演示

这篇关于CDK数据表或Material2数据表是否有索引属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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