type SortMethod<T> = (a: T, b: T) => number;
export class ColumnSetting<T> {
constructor(
public headerLabel: string,
public extract: (input: T) => string,
public sort?: SortMethod<T>
) {
this.headerLabel = headerLabel;
this.extract = extract;
this.sort = sort;
}
}
import { ColumnSetting } from '@enterprise/prod/shared/table-layout/shared/layout/column-setting.model';
@Component({
selector: 'practice-table',
templateUrl: './practice-table.component.html',
styleUrls: ['./practice-table.component.scss'],
})
export class PracticeTableComponent implements OnInit {
tableData?: any;
tableSettings: ColumnSetting<IAuditLog>[] = [
new ColumnSetting<any>(
'Date / Time',
x => x.formattedDate,
(a: IAuditLog, b: IAuditLog) =>
new Date(b.formattedDate).valueOf() -
new Date(a.formattedDate).valueOf(),
),
new ColumnSetting<any>(
'User',
x => x.userName,
(a: IAuditLog, b: IAuditLog) => a.userName.localeCompare(b.userName),
),
new ColumnSetting<any>(
'Type',
x => x.displayType,
(a: IAuditLog, b: IAuditLog) =>
a.displayType.localeCompare(b.displayType),
),
];
<table class="table-row-layout">
<!-- TABLE HEADER -->
<thead>
<tr class="col-header" scope="row">
<ng-container *ngFor="let map of tableSettings; let i = index">
<!-- COLUMN HEADER -->
<th class="col col-{{ i + 1 }}" scope="col" role="columnheader">
<!-- NOT SORTABLE -->
<ng-container *ngIf="!map.sort">
{{ map.headerLabel }}
</ng-container>
<!-- SORTABLE -->
<ng-container *ngIf="map.sort">
<app-sort-button
[sort]="map.sort"
[label]="map.headerLabel">
</app-sort-button>
</ng-container>
</th>
</ng-container>
</tr>
</thead>
<!-- TABLE BODY -->
<tbody>
<tr *ngFor="let data of tableData">
<ng-container *ngFor="let map of tableSettings; let i = index">
<!-- TABLE DATA -->
<td class="col col-{{ i + 1 }}
headers="{{ map.headerLabel }}">
{{ map.extract(data) }}
</td>
</ng-container>
</tr>
</tbody>
</table>
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/dab8e022-fb3a-4014-8986-14e8fd3c9134%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/b7c75d83-badb-4b00-a2c0-7bb9c3db8151%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/516a4325-a6ac-4856-bb06-2d8fb37ebd42%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/516a4325-a6ac-4856-bb06-2d8fb37ebd42%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/CAEwHGW3kRmAng8JNaAH98%2Bnpu4z%2BX%3DXt-7ZfWhsdYtKoCrq9Mg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/A1EA2DFA-6FCF-49F4-8AD9-622288630DB2%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/CALz16eEZ9YGBYbe7%2B1dLLUewRKERQCeOeWgsyG2M_pfJMjCWJg%40mail.gmail.com.