group management, add sort on all columns

This commit is contained in:
Sylvain MATHIEU 2021-12-13 15:32:51 +01:00
parent 596a11210f
commit 2e2a59f6f2
2 changed files with 11 additions and 4 deletions

View File

@ -23,19 +23,19 @@
</ng-container>
<ng-container matColumnDef="created_at">
<th mat-header-cell *matHeaderCellDef> Creation date</th>
<th mat-header-cell *matHeaderCellDef mat-sort-header> Creation date</th>
<td mat-cell *matCellDef="let element"> {{element.created_at}} </td>
</ng-container>
<ng-container matColumnDef="updated_at">
<th mat-header-cell *matHeaderCellDef> last update</th>
<th mat-header-cell *matHeaderCellDef mat-sort-header> last update</th>
<td mat-cell *matCellDef="let element"> {{element.updated_at}} </td>
</ng-container>
<ng-container matColumnDef="is_builtin">
<th mat-header-cell *matHeaderCellDef> is build in</th>
<th mat-header-cell *matHeaderCellDef mat-sort-header> is build in</th>
<td mat-cell *matCellDef="let element"> {{element.is_builtin}} </td>
</ng-container>

View File

@ -66,13 +66,20 @@ export class GroupManagementComponent implements OnInit {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'name':
return compare(a.name, b.name, isAsc);
return compare(a.name.toLowerCase(), b.name.toLowerCase(), isAsc);
case 'created_at':
return compare(a.created_at, b.created_at, isAsc);
case 'updated_at':
return compare(a.updated_at, b.updated_at, isAsc);
case 'is_builtin':
return compare(a.is_builtin.toString(), b.is_builtin.toString(), isAsc);
default:
return 0;
}
});
function compare(a: number | string, b: number | string, isAsc: boolean) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}
}