Merge pull request #3791 from vvlladd28/improvement/table/trackBy
UI: Added trackBy in table widget
This commit is contained in:
commit
d8d04debbd
@ -61,7 +61,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
<div fxFlex class="table-container">
|
<div fxFlex class="table-container">
|
||||||
<table mat-table [dataSource]="alarmsDatasource" [trackBy]="trackByRowIndex"
|
<table mat-table [dataSource]="alarmsDatasource" [trackBy]="trackByAlarmId"
|
||||||
matSort [matSortActive]="sortOrderProperty" [matSortDirection]="pageLinkSortDirection()" matSortDisableClear>
|
matSort [matSortActive]="sortOrderProperty" [matSortDirection]="pageLinkSortDirection()" matSortDisableClear>
|
||||||
<ng-container matColumnDef="select" sticky>
|
<ng-container matColumnDef="select" sticky>
|
||||||
<mat-header-cell *matHeaderCellDef style="width: 30px;">
|
<mat-header-cell *matHeaderCellDef style="width: 30px;">
|
||||||
@ -96,7 +96,7 @@
|
|||||||
width: (actionCellDescriptors.length * 40) + 'px' }">
|
width: (actionCellDescriptors.length * 40) + 'px' }">
|
||||||
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
||||||
<button mat-button mat-icon-button [disabled]="(isLoading$ | async) || !actionEnabled(alarm, actionDescriptor)"
|
<button mat-button mat-icon-button [disabled]="(isLoading$ | async) || !actionEnabled(alarm, actionDescriptor)"
|
||||||
*ngFor="let actionDescriptor of actionCellDescriptors"
|
*ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
matTooltip="{{ actionDescriptor.displayName }}"
|
matTooltip="{{ actionDescriptor.displayName }}"
|
||||||
matTooltipPosition="above"
|
matTooltipPosition="above"
|
||||||
(click)="onActionButtonClick($event, alarm, actionDescriptor)">
|
(click)="onActionButtonClick($event, alarm, actionDescriptor)">
|
||||||
@ -110,7 +110,7 @@
|
|||||||
<mat-icon class="material-icons">more_vert</mat-icon>
|
<mat-icon class="material-icons">more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
||||||
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors"
|
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
[disabled]="(isLoading$ | async) || !actionEnabled(alarm, actionDescriptor)"
|
[disabled]="(isLoading$ | async) || !actionEnabled(alarm, actionDescriptor)"
|
||||||
(click)="onActionButtonClick($event, alarm, actionDescriptor)">
|
(click)="onActionButtonClick($event, alarm, actionDescriptor)">
|
||||||
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
||||||
|
|||||||
@ -563,8 +563,12 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
|
|||||||
return column.def;
|
return column.def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public trackByRowIndex(index: number) {
|
public trackByAlarmId(index: number, alarm: AlarmData) {
|
||||||
return index;
|
return alarm.id.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public trackByActionCellDescriptionId(index: number, action: WidgetActionDescriptor) {
|
||||||
|
return action.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public headerStyle(key: EntityColumn): any {
|
public headerStyle(key: EntityColumn): any {
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
<div fxFlex class="table-container">
|
<div fxFlex class="table-container">
|
||||||
<table mat-table [dataSource]="entityDatasource" [trackBy]="trackByRowIndex"
|
<table mat-table [dataSource]="entityDatasource" [trackBy]="trackByEntityId"
|
||||||
matSort [matSortActive]="sortOrderProperty" [matSortDirection]="pageLinkSortDirection()" matSortDisableClear>
|
matSort [matSortActive]="sortOrderProperty" [matSortDirection]="pageLinkSortDirection()" matSortDisableClear>
|
||||||
<ng-container [matColumnDef]="column.def" *ngFor="let column of columns; trackBy: trackByColumnDef;">
|
<ng-container [matColumnDef]="column.def" *ngFor="let column of columns; trackBy: trackByColumnDef;">
|
||||||
<mat-header-cell [ngStyle]="headerStyle(column)" *matHeaderCellDef mat-sort-header> {{ column.title }} </mat-header-cell>
|
<mat-header-cell [ngStyle]="headerStyle(column)" *matHeaderCellDef mat-sort-header> {{ column.title }} </mat-header-cell>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
width: (actionCellDescriptors.length * 40) + 'px' }">
|
width: (actionCellDescriptors.length * 40) + 'px' }">
|
||||||
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
||||||
<button mat-button mat-icon-button [disabled]="isLoading$ | async"
|
<button mat-button mat-icon-button [disabled]="isLoading$ | async"
|
||||||
*ngFor="let actionDescriptor of actionCellDescriptors"
|
*ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
matTooltip="{{ actionDescriptor.displayName }}"
|
matTooltip="{{ actionDescriptor.displayName }}"
|
||||||
matTooltipPosition="above"
|
matTooltipPosition="above"
|
||||||
(click)="onActionButtonClick($event, entity, actionDescriptor)">
|
(click)="onActionButtonClick($event, entity, actionDescriptor)">
|
||||||
@ -71,7 +71,7 @@
|
|||||||
<mat-icon class="material-icons">more_vert</mat-icon>
|
<mat-icon class="material-icons">more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
||||||
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors"
|
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
[disabled]="isLoading$ | async"
|
[disabled]="isLoading$ | async"
|
||||||
(click)="onActionButtonClick($event, entity, actionDescriptor)">
|
(click)="onActionButtonClick($event, entity, actionDescriptor)">
|
||||||
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
||||||
|
|||||||
@ -486,8 +486,12 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
|
|||||||
return column.def;
|
return column.def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public trackByRowIndex(index: number) {
|
public trackByEntityId(index: number, entity: EntityData) {
|
||||||
return index;
|
return entity.id.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public trackByActionCellDescriptionId(index: number, action: WidgetActionDescriptor) {
|
||||||
|
return action.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public headerStyle(key: EntityColumn): any {
|
public headerStyle(key: EntityColumn): any {
|
||||||
|
|||||||
@ -39,9 +39,9 @@
|
|||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
<mat-tab-group [ngClass]="{'tb-headless': sources.length === 1}" fxFlex
|
<mat-tab-group [ngClass]="{'tb-headless': sources.length === 1}" fxFlex
|
||||||
[(selectedIndex)]="sourceIndex" (selectedIndexChange)="onSourceIndexChanged()">
|
[(selectedIndex)]="sourceIndex" (selectedIndexChange)="onSourceIndexChanged()">
|
||||||
<mat-tab *ngFor="let source of sources" label="{{ source.datasource.name }}">
|
<mat-tab *ngFor="let source of sources; trackBy: trackBySourcesIndex" label="{{ source.datasource.name }}">
|
||||||
<div fxFlex class="table-container">
|
<div fxFlex class="table-container">
|
||||||
<table mat-table [dataSource]="source.timeseriesDatasource" [trackBy]="trackByRowIndex"
|
<table mat-table [dataSource]="source.timeseriesDatasource" [trackBy]="trackByRowTimestamp"
|
||||||
matSort [matSortActive]="source.pageLink.sortOrder.property" [matSortDirection]="source.pageLink.sortDirection()" matSortDisableClear>
|
matSort [matSortActive]="source.pageLink.sortOrder.property" [matSortDirection]="source.pageLink.sortDirection()" matSortDisableClear>
|
||||||
<ng-container *ngIf="showTimestamp" [matColumnDef]="'0'">
|
<ng-container *ngIf="showTimestamp" [matColumnDef]="'0'">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Timestamp</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header>Timestamp</mat-header-cell>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
width: (actionCellDescriptors.length * 40) + 'px' }">
|
width: (actionCellDescriptors.length * 40) + 'px' }">
|
||||||
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
<div fxHide fxShow.gt-md fxFlex fxLayout="row" fxLayoutAlign="end">
|
||||||
<button mat-button mat-icon-button [disabled]="isLoading$ | async"
|
<button mat-button mat-icon-button [disabled]="isLoading$ | async"
|
||||||
*ngFor="let actionDescriptor of actionCellDescriptors"
|
*ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
matTooltip="{{ actionDescriptor.displayName }}"
|
matTooltip="{{ actionDescriptor.displayName }}"
|
||||||
matTooltipPosition="above"
|
matTooltipPosition="above"
|
||||||
(click)="onActionButtonClick($event, row, actionDescriptor)">
|
(click)="onActionButtonClick($event, row, actionDescriptor)">
|
||||||
@ -81,7 +81,7 @@
|
|||||||
<mat-icon class="material-icons">more_vert</mat-icon>
|
<mat-icon class="material-icons">more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
<mat-menu #cellActionsMenu="matMenu" xPosition="before">
|
||||||
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors"
|
<button mat-menu-item *ngFor="let actionDescriptor of actionCellDescriptors; trackBy: trackByActionCellDescriptionId"
|
||||||
[disabled]="isLoading$ | async"
|
[disabled]="isLoading$ | async"
|
||||||
(click)="onActionButtonClick($event, row, actionDescriptor)">
|
(click)="onActionButtonClick($event, row, actionDescriptor)">
|
||||||
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
<mat-icon>{{actionDescriptor.icon}}</mat-icon>
|
||||||
|
|||||||
@ -366,8 +366,16 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
|
|||||||
return header.index;
|
return header.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public trackByRowIndex(index: number) {
|
public trackByRowTimestamp(index: number, row: TimeseriesRow) {
|
||||||
return index;
|
return row[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public trackByActionCellDescriptionId(index: number, action: WidgetActionDescriptor) {
|
||||||
|
return action.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public trackBySourcesIndex(index: number, source: TimeseriesTableSource) {
|
||||||
|
return source.datasource.entityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cellStyle(source: TimeseriesTableSource, index: number, value: any): any {
|
public cellStyle(source: TimeseriesTableSource, index: number, value: any): any {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user