@ea-controls/mat-table-extensions 19.0.3 → 19.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -36
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,63 +1,162 @@
|
|
1
1
|
# MatTableExtensions
|
2
2
|
|
3
|
-
|
3
|
+
Angular directives that allows to extend Angular [mat-table](https://material.angular.io/components/table/overview) features
|
4
4
|
|
5
|
-
##
|
5
|
+
## Multiple Headers/Footer
|
6
6
|
|
7
|
-
|
7
|
+
Usually mat-table only allows one header and footer inside [matColumnDef] directive
|
8
8
|
|
9
|
-
```
|
10
|
-
|
9
|
+
```html
|
10
|
+
<table mat-table>
|
11
|
+
<ng-container matColumnDef="position">
|
12
|
+
<th mat-header-cell *matHeaderCellDef> No. </th> <!-- Only one header -->
|
13
|
+
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
|
14
|
+
</ng-container>
|
15
|
+
|
16
|
+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
17
|
+
</table>
|
11
18
|
```
|
12
19
|
|
13
|
-
|
20
|
+
With current library, now you can add more of them
|
21
|
+
|
22
|
+
```html
|
23
|
+
<table mat-table>
|
24
|
+
<ng-container matColumnDef="position">
|
25
|
+
<th mat-header-cell *matHeaderCellDef> No. </th>
|
26
|
+
<th mat-header-cell *matExtraHeaderCellDef="'extra-header-name'"> Extra Header </th> <!-- Extra header cell-->
|
27
|
+
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
|
28
|
+
</ng-container>
|
14
29
|
|
15
|
-
|
16
|
-
|
30
|
+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
31
|
+
<tr mat-header-row *matExtraHeaderRowDef="displayedColumns; name: 'extra-header-name'"></tr> <!-- Extra header row -->
|
32
|
+
</table>
|
17
33
|
```
|
18
34
|
|
19
|
-
|
35
|
+
### Steps
|
36
|
+
|
37
|
+
1. Import `MatExtraTableModule`
|
38
|
+
1. Add new `*matExtraHeaderCellDef` instead `*matHeaderCellDef` for extra headers
|
39
|
+
1. You have to send any string value as cell identifier
|
40
|
+
> Replace `extra-header-name` with your custom name
|
41
|
+
1. Notice you can use `*matHeaderRowDef` normally, new directive is only used when you need extra header cell
|
42
|
+
1. Add new `*matExtraHeaderRowDef` instead `*matHeaderRowDef` for extra rows using extra header cells
|
43
|
+
1. `name` is required to find extra header, it have to be the same use in `matExtraHeaderCellDef` attribute
|
44
|
+
> *matExtraHeaderRowDef="displayedColumns; `name`: 'extra-header-name'>"
|
45
|
+
1. Notice you can use `*matHeaderRowDef` normally, new directive is only used when you need extra header row
|
46
|
+
1. Similar tags you can use when extra footer is required
|
47
|
+
|
48
|
+
```html
|
49
|
+
<td mat-footer-cell *matExtraFooterCellDef="'extra-footer-name'">Footer</th> <!-- Extra footer cell -->
|
50
|
+
```
|
20
51
|
|
21
|
-
|
52
|
+
```html
|
53
|
+
<tr mat-header-row *matExtraFooterRowDef="displayedColumns; name: 'extra-footer-name'"></tr> <!-- Extra footer row -->
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
### Full example
|
58
|
+
|
59
|
+
```ts
|
60
|
+
|
61
|
+
import { MatExtraTableModule } from '@ea-controls/mat-table-extensions';
|
62
|
+
|
63
|
+
export interface PeriodicElement {
|
64
|
+
name: string;
|
65
|
+
position: number;
|
66
|
+
weight: number;
|
67
|
+
symbol: string;
|
68
|
+
}
|
69
|
+
|
70
|
+
const ELEMENT_DATA: PeriodicElement[] = [
|
71
|
+
{ position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H' },
|
72
|
+
{ position: 2, name: 'Helium', weight: 4.0026, symbol: 'He' },
|
73
|
+
{ position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li' },
|
74
|
+
{ position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be' },
|
75
|
+
{ position: 5, name: 'Boron', weight: 10.811, symbol: 'B' },
|
76
|
+
{ position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C' },
|
77
|
+
{ position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N' },
|
78
|
+
{ position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O' },
|
79
|
+
{ position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F' },
|
80
|
+
{ position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne' },
|
81
|
+
];
|
82
|
+
|
83
|
+
@Component({
|
84
|
+
selector: 'app-basic',
|
85
|
+
imports: [MatExtraTableModule],
|
86
|
+
templateUrl: './basic.component.html'
|
87
|
+
})
|
88
|
+
export class BasicComponent {
|
89
|
+
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
|
90
|
+
dataSource = ELEMENT_DATA;
|
91
|
+
}
|
22
92
|
|
23
|
-
```bash
|
24
|
-
ng build mat-table-extensions
|
25
93
|
```
|
26
94
|
|
27
|
-
|
95
|
+
```html
|
96
|
+
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
|
28
97
|
|
29
|
-
|
98
|
+
<!-- POSITION -->
|
99
|
+
<ng-container matColumnDef="position">
|
100
|
+
<th mat-header-cell *matHeaderCellDef> 1. from html </th>
|
101
|
+
<th mat-header-cell *matExtraHeaderCellDef="'filter'">
|
102
|
+
<input type="text">
|
103
|
+
</th>
|
30
104
|
|
31
|
-
|
105
|
+
<td mat-cell *matCellDef="let data"> xxxxxxxxxx from html </td>
|
32
106
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
```
|
107
|
+
<td mat-footer-cell *matFooterCellDef> f1 </td>
|
108
|
+
<th mat-footer-cell *matExtraFooterCellDef="'filter'" [attr.colspan]="2">f2</th>
|
109
|
+
</ng-container>
|
37
110
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
111
|
+
<!-- NAME -->
|
112
|
+
<ng-container matColumnDef="name">
|
113
|
+
<th mat-header-cell *matHeaderCellDef> Name </th>
|
114
|
+
<th mat-header-cell *matExtraHeaderCellDef="'filter'">
|
115
|
+
<input type="text">
|
116
|
+
</th>
|
42
117
|
|
43
|
-
|
118
|
+
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
|
44
119
|
|
45
|
-
|
120
|
+
<td mat-footer-cell *matFooterCellDef> f1 </td>
|
121
|
+
<th mat-footer-cell *matExtraFooterCellDef="'filter'" [attr.colspan]="4">f2</th>
|
122
|
+
</ng-container>
|
46
123
|
|
47
|
-
|
48
|
-
ng
|
49
|
-
|
124
|
+
<!-- WEIGHT -->
|
125
|
+
<ng-container matColumnDef="weight">
|
126
|
+
<th mat-header-cell *matHeaderCellDef> Weight </th>
|
127
|
+
<th mat-header-cell *matExtraHeaderCellDef="'filter'">
|
128
|
+
<input type="text">
|
129
|
+
</th>
|
50
130
|
|
51
|
-
|
131
|
+
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
|
52
132
|
|
53
|
-
|
133
|
+
<td mat-footer-cell *matFooterCellDef> f1 </td>
|
134
|
+
</ng-container>
|
54
135
|
|
55
|
-
|
56
|
-
ng
|
57
|
-
|
136
|
+
<!-- SYMBOL -->
|
137
|
+
<ng-container matColumnDef="symbol">
|
138
|
+
<th mat-header-cell *matHeaderCellDef> Symbol </th>
|
139
|
+
<th mat-header-cell *matExtraHeaderCellDef="'filter'">
|
140
|
+
<input type="text">
|
141
|
+
</th>
|
142
|
+
|
143
|
+
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
|
144
|
+
|
145
|
+
<td mat-footer-cell *matFooterCellDef> f1 </td>
|
146
|
+
</ng-container>
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
<!-- HEADERS -->
|
151
|
+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
152
|
+
<tr mat-header-row *matExtraHeaderRowDef="displayedColumns; name: 'filter'"></tr>
|
58
153
|
|
59
|
-
|
154
|
+
<!-- CELLS -->
|
155
|
+
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
60
156
|
|
61
|
-
|
157
|
+
<!-- FOOTER -->
|
158
|
+
<tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
|
159
|
+
<tr mat-footer-row *matExtraFooterRowDef="['position', 'name']; name: 'filter'"></tr>
|
62
160
|
|
63
|
-
|
161
|
+
</table>
|
162
|
+
```
|