angular - 在angular2中按类颜色排序
问题描述
我正在尝试根据单选按钮(element.IsOnline)的颜色对表格进行排序。我正在尝试按上次看到的日期排序,但即使格式似乎没问题,也没有排序。这就是为什么我试图用绿色或红色来做,但不知道我该怎么做。
我该怎么做?
我的.html
<table mat-table [dataSource]="dataSource" matSort class=" mat-elevation-z8">
<ng-container matColumnDef="online">
<th mat-header-cell *matHeaderCellDef mat-sort-header></th>
<td mat-cell *matCellDef="let element">
<i *ngIf="element.isOnline" class="material-icons"
style="color: rgba(0, 100, 0, 0.80)">radio_button_checked</i>
<i *ngIf="!element.isOnline" class="material-icons"
style="color: rgba(190, 0, 0, 0.80)">radio_button_checked</i>
</td>
</ng-container>
<ng-container matColumnDef="deviceName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Device Id </th>
<td mat-cell *matCellDef="let element"> {{element.deviceName}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let element; columns: displayedColumns;" (click)="goToDeviceDetails(element)">
</tr>
<ng-container matColumnDef="lastSeen">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Last seen </th>
<td mat-cell *matCellDef="let element"> {{element.telemetryUtc | date: 'medium'}} </td>
</ng-container>
</table>
我的 .ts
import { Component, OnInit, OnDestroy, ViewEncapsulation, ViewChild } from "@angular/core";
import { MatSort } from '@angular/material/sort';
@Component({
selector: "app-provisioned-list",
templateUrl: "./provisioned-list.component.html",
styleUrls: ["./provisioned-list.component.scss"],
encapsulation: ViewEncapsulation.None,
animations: fuseAnimations
})
export class ProvisionedListComponent implements OnInit, OnDestroy {
deviceList: DeviceModel[];
displayedColumns: string[] = ["checkbox", "online", "deviceName", "tags", "actualVersion", "status", "runningApps", "appVersion", "lastSeen"];
@ViewChild(MatSort) sort: MatSort;
devices: any;
private getDeviceList() {
this.provisionedService.getProvisionedDevicesList().then(response => {
this.deviceErrorMessage = null;
this.dataSource.data = response;
this.dataSource.data.map(device => {
this.provisionedService.getIsDeviceAlive(device._id).then(response => device.isOnline = response);
}
解决方案
推荐阅读
- asp.net - 为什么一个asp.net web 服务会占用这么多内存?
- react-native - SWIFT_VERSION '5.0' 不受支持,支持的版本有:3.0、4.0、4.2。(在目标“SwiftyJSON”中)
- python - 如何比较预测频率数据与实际频率数据?
- php - 编辑 FTP 文件夹上的 XML 文件
- angularjs - 如何在 md-option 中添加 md-icon?
- r - 如何用曲线图显示不同时间的频率
- javascript - o数据服务调用序列
- ruby-on-rails - 在 Ruby on Rails 中从多对多关系解析数据
- powershell - 将具有今天日期的目录中的文件复制到另一个位置
- java - 如何运行 Spring RMI 服务器?