Sort players by id

This commit is contained in:
Michel ten Voorde
2024-11-08 10:39:21 +01:00
parent e8b0303660
commit b48623f77e
2 changed files with 5 additions and 5 deletions

View File

@@ -5,9 +5,9 @@
<input matInput (keyup)="filterPlayersList($event)" #input>
</mat-form-field>
<div>
<table mat-table [dataSource]="dataSource" matSort matSortActive="name" matSortDirection="asc">
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef>#</th>
<table mat-table [dataSource]="dataSource" matSort matSortActive="id" matSortDirection="asc">
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>#</th>
<td mat-cell *matCellDef="let player">{{ player.id }}</td>
</ng-container>
<ng-container matColumnDef="name">

View File

@@ -34,7 +34,7 @@ export class PlayerListComponent implements AfterViewInit {
players: Player[];
displayedColumns: string[] = ['position', 'name', 'sex', 'club', 'action'];
displayedColumns: string[] = ['id', 'name', 'sex', 'club', 'action'];
dataSource: MatTableDataSource<Player>
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@@ -53,9 +53,9 @@ export class PlayerListComponent implements AfterViewInit {
this.dataSource.paginator = this.paginator;
this.dataSource.sortingDataAccessor = (item, header) => {
switch (header) {
case 'id': return item.id;
case 'club': return item.club;
default: return item.lastName + item.firstName;
// case 'name': return this.fullNamePipe.transform(item);
}
}
this.dataSource.sort = this.sort;