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

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

问题描述

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

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一样获得行索引,在<md-row>

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;
}

柱塞演示

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

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