Relationships
Depends on
-
MatTableModule
-
MatSortModule
|
reportData
|
Type : unknown[]
|
Default value : []
|
|
|
|
columns
|
Type : string[]
|
Default value : ["Name", "Count"]
|
|
|
|
dataSource
|
Type : unknown
|
Default value : new MatTableDataSource()
|
|
|
|
isError
|
Type : unknown
|
Default value : false
|
|
|
|
sqlReportService
|
Type : unknown
|
Default value : inject(SqlReportService)
|
|
|
import {
Component,
inject,
ChangeDetectionStrategy,
effect,
input,
} from "@angular/core";
import { SqlReport } from "../../report-config";
import { MatTableDataSource, MatTableModule } from "@angular/material/table";
import { MatSortModule } from "@angular/material/sort";
import { SqlReportService } from "../../sql-report/sql-report.service";
import { Logging } from "../../../../core/logging/logging.service";
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-sql-v2-table",
imports: [MatTableModule, MatSortModule],
templateUrl: "./sql-v2-table.component.html",
styleUrl: "./sql-v2-table.component.scss",
})
export class SqlV2TableComponent {
sqlReportService = inject(SqlReportService);
report = input<SqlReport>();
reportData = input<unknown[]>([]);
isError = false;
dataSource = new MatTableDataSource();
columns: string[] = ["Name", "Count"];
constructor() {
effect(() => {
try {
this.dataSource.data = this.sqlReportService.flattenData(
this.reportData(),
);
this.isError = false;
} catch (error) {
Logging.error(error);
this.isError = true;
this.dataSource.data = [];
}
});
}
}
<table
mat-table
[dataSource]="dataSource"
class="data-table"
i18n-aria-label="Label for table showing report result"
aria-label="Table showing the report results"
>
<ng-container matColumnDef="Name">
<th mat-header-cell *matHeaderCellDef i18n>Name</th>
<td
mat-cell
*matCellDef="let row"
[style.padding-left.px]="16 + row.level * 20"
>
{{ row.key }}
</td>
</ng-container>
<ng-container matColumnDef="Count">
<th mat-header-cell *matHeaderCellDef i18n>Count</th>
<td mat-cell *matCellDef="let row">
{{ row.value }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns; index as i"></tr>
<tr
mat-row
class="row"
*matRowDef="let row; columns: columns; index as i"
[class.bg-even]="i % 2 === 0"
></tr>
</table>
.data-table {
width: 100%;
line-height: 1.5;
}
.row:hover {
background: #ececec;
}
.bg-even {
background: #fafafa;
}
Legend
Html element with directive