Angular 角度材质表-使用代码选择行
我正在开发一个Angular 5应用程序,有一个Angular Material表显示一些数据。我希望用户能够选择表外的图形项目,并在Angular 角度材质表-使用代码选择行,angular,angular-material,Angular,Angular Material,我正在开发一个Angular 5应用程序,有一个Angular Material表显示一些数据。我希望用户能够选择表外的图形项目,并在功能中单击在我的表中选择适当的行 我尝试创建Mat表的ViewChild,但似乎无法获取对所选行的引用。这个定义似乎也没有提供任何线索。这是我的桌子: <!-- Table --> <div id="table-container" style="height: 240px; width: 100%; overfl
功能中单击
在我的表中选择适当的行
我尝试创建Mat表的ViewChild
,但似乎无法获取对所选行的引用。这个定义似乎也没有提供任何线索。这是我的桌子:
<!-- Table -->
<div id="table-container" style="height: 240px; width: 100%; overflow: auto;">
<mat-table #table
class="mat-table"
[dataSource]="dataSource"
style="height: 100%; padding: 0px; margin: 0px; border-top: 1px solid rgba(0, 0, 0, 0.12);">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Device Name Column -->
<ng-container matColumnDef="DeviceName">
<mat-header-cell *matHeaderCellDef mat-sort-header> Device </mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.deviceName}} </mat-cell>
</ng-container>
<!-- Location Name Column -->
<ng-container matColumnDef="LocationName">
<mat-header-cell *matHeaderCellDef mat-sort-header> Location </mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.locationName}} </mat-cell>
</ng-container>
<!-- Header Row -->
<mat-header-row *matHeaderRowDef=""></mat-header-row>
<!--<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>-->
<!-- Row Definition -->
<mat-row *matRowDef="let row; columns: displayedColumns; let index=index;"
[ngClass]="setRowClass(index)"
(click)="onClickRow(row, $event, index)"
(mouseenter)="onMouseEnterRow(index)"
(mouseleave)="onMouseLeaveRow(index)">
</mat-row>
</mat-table>
</div>
装置
{{item.deviceName}
位置
{{item.locationName}
任何建议都是非常受欢迎的。谢谢。为了澄清,您是否正在寻找类似以下内容的流程:用户单击图形项目,可能会选择表中特定行的按钮
->?如果是这种情况,您可以为行指定一个selected
键,以便在mat行定义中的[ngClass]
中,您可以执行类似于[ngClass]=“{select-row':row.selected}”的操作,在选定行后为行指定图形差异。至于所选行的功能,则取决于选中一行后您希望发生什么。您在流程中是正确的,请单击按钮->选择行。在用户单击后,比如说按钮,我希望用户能够单击屏幕上的另一项,该项将更新当前选定行的数据。我将审查您的建议,一旦我回到代码,并回答任何结果后。谢谢