-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathtable-sorting-example.ts
139 lines (133 loc) · 3.6 KB
/
table-sorting-example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {AfterViewInit, Component, ViewChild, inject} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {MatButtonToggleModule} from '@angular/material/button-toggle';
import {MatSort, Sort, MatSortModule} from '@angular/material/sort';
import {MatTableDataSource, MatTableModule} from '@angular/material/table';
export interface EmployeeData {
firstName: string;
lastName: string;
position: string;
office: string;
salary: number;
}
const EMPLOYEE_DATA: EmployeeData[] = [
{
firstName: 'Garrett',
lastName: 'Winters',
position: 'Accountant',
office: 'Tokyo',
salary: 170750,
},
{firstName: 'Airi', lastName: 'Satou', position: 'Accountant', office: 'Tokyo', salary: 162700},
{
firstName: 'Donna',
lastName: 'Snider',
position: 'Customer Support',
office: 'New York',
salary: 112000,
},
{
firstName: 'Serge',
lastName: 'Baldwin',
position: 'Data Coordinator',
office: 'Singapore',
salary: 138575,
},
{firstName: 'Thor', lastName: 'Walton', position: 'Developer', office: 'New York', salary: 98540},
{
firstName: 'Gavin',
lastName: 'Joyce',
position: 'Developer',
office: 'Edinburgh',
salary: 92575,
},
{firstName: 'Suki', lastName: 'Burks', position: 'Developer', office: 'London', salary: 114500},
{
firstName: 'Jonas',
lastName: 'Alexander',
position: 'Developer',
office: 'San Francisco',
salary: 86500,
},
{
firstName: 'Jackson',
lastName: 'Bradshaw',
position: 'Director',
office: 'New York',
salary: 645750,
},
{
firstName: 'Brielle',
lastName: 'Williamson',
position: 'Integration Specialist',
office: 'New York',
salary: 372000,
},
{
firstName: 'Michelle',
lastName: 'House',
position: 'Integration Specialist',
office: 'Sydney',
salary: 95400,
},
{
firstName: 'Michael',
lastName: 'Bruce',
position: 'Javascript Developer',
office: 'Singapore',
salary: 183000,
},
{
firstName: 'Ashton',
lastName: 'Cox',
position: 'Junior Technical Author',
office: 'San Francisco',
salary: 86000,
},
{
firstName: 'Michael',
lastName: 'Silva',
position: 'Marketing Designer',
office: 'London',
salary: 198500,
},
{
firstName: 'Timothy',
lastName: 'Mooney',
position: 'Office Manager',
office: 'London',
salary: 136200,
},
];
/**
* @title Table with sorting
*/
@Component({
selector: 'table-sorting-example',
styleUrl: 'table-sorting-example.css',
templateUrl: 'table-sorting-example.html',
imports: [MatTableModule, MatSortModule, FormsModule, MatButtonToggleModule],
})
export class TableSortingExample implements AfterViewInit {
private _liveAnnouncer = inject(LiveAnnouncer);
multiSortEnabled = false;
displayedColumns: string[] = ['firstName', 'lastName', 'position', 'office', 'salary'];
dataSource = new MatTableDataSource(EMPLOYEE_DATA);
@ViewChild(MatSort) sort: MatSort;
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
/** Announce the change in sort state for assistive technology. */
announceSortChange(sortState: Sort) {
// This example uses English messages. If your application supports
// multiple language, you would internationalize these strings.
// Furthermore, you can customize the message to add additional
// details about the values being sorted.
if (sortState.direction) {
this._liveAnnouncer.announce(`Sorted ${sortState.direction}ending`);
} else {
this._liveAnnouncer.announce('Sorting cleared');
}
}
}