Skip to content

Commit bef12e6

Browse files
authored
feat(module:table): support nzFixed for nzSummary (#8642)
* feat(module:table): support `nzFixed` for `nzSummary` * feat(module:table): support `nzFixed` for `nzSummary`
1 parent 6fc1c78 commit bef12e6

19 files changed

+383
-210
lines changed

components/table/demo/summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ title:
77

88
## zh-CN
99

10-
通过 `nzSummary` 设置总结栏。
10+
通过 `nzSummary` 设置总结栏。可以通过配置 `nzFixed` 属性使其固定。
1111

1212
## en-US
1313

14-
Set summary content by `nzSummary` prop.
14+
Set summary content by `nzSummary` prop. You can fixed it by set `nzFixed` prop.

components/table/demo/summary.ts

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import { Component, OnInit } from '@angular/core';
1212
</tr>
1313
</thead>
1414
<tbody>
15-
<tr *ngFor="let data of middleTable.data">
16-
<td>{{ data.name }}</td>
17-
<td>{{ data.borrow }}</td>
18-
<td>{{ data.repayment }}</td>
19-
</tr>
20-
<tr></tr>
15+
@for (data of middleTable.data; track $index) {
16+
<tr>
17+
<td>{{ data.name }}</td>
18+
<td>{{ data.borrow }}</td>
19+
<td>{{ data.repayment }}</td>
20+
</tr>
21+
}
2122
</tbody>
2223
<tfoot nzSummary>
2324
<tr>
@@ -37,12 +38,42 @@ import { Component, OnInit } from '@angular/core';
3738
</tr>
3839
</tfoot>
3940
</nz-table>
41+
42+
<br />
43+
44+
<nz-table
45+
#fixedTable
46+
nzBordered
47+
[nzData]="fixedData"
48+
[nzShowPagination]="false"
49+
[nzScroll]="{ x: '1280px', y: '500px' }"
50+
>
51+
<thead>
52+
<tr>
53+
<th>Name</th>
54+
<th>Description</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
@for (data of fixedTable.data; track data.key) {
59+
<tr>
60+
<td>{{ data.name }}</td>
61+
<td>{{ data.description }}</td>
62+
</tr>
63+
}
64+
</tbody>
65+
<tfoot nzSummary nzFixed>
66+
<tr>
67+
<td>Summary</td>
68+
<td>This is a summary content</td>
69+
</tr>
70+
</tfoot>
71+
</nz-table>
4072
`,
4173
styles: [
4274
`
43-
tfoot th,
44-
tfoot td {
45-
background: #fafafa;
75+
:host ::ng-deep tfoot.ant-table-summary {
76+
background-color: #fafafa !important;
4677
}
4778
`
4879
]
@@ -71,13 +102,22 @@ export class NzDemoTableSummaryComponent implements OnInit {
71102
}
72103
];
73104

74-
fixedData: Array<{ name: string; description: string }> = [];
105+
fixedData: Array<{ key: number; name: string; description: string }> = [];
75106
totalBorrow = 0;
76107
totalRepayment = 0;
108+
77109
ngOnInit(): void {
78110
this.data.forEach(({ borrow, repayment }) => {
79111
this.totalBorrow += borrow;
80112
this.totalRepayment += repayment;
81113
});
114+
115+
for (let i = 0; i < 20; i += 1) {
116+
this.fixedData.push({
117+
key: i,
118+
name: ['Light', 'Bamboo', 'Little'][i % 3],
119+
description: 'Everything that has a beginning, has an end.'
120+
});
121+
}
82122
}
83123
}

components/table/doc/index.en-US.md

Lines changed: 29 additions & 30 deletions
Large diffs are not rendered by default.

components/table/doc/index.zh-CN.md

Lines changed: 119 additions & 118 deletions
Large diffs are not rendered by default.

components/table/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export * from './src/table/table-virtual-scroll.directive';
1616
export * from './src/table/table-fixed-row.component';
1717
export * from './src/table/tbody.component';
1818
export * from './src/table/thead.component';
19-
export * from './src/table/tfoot-summary.directive';
19+
export * from './src/table/tfoot-summary.component';
2020
export * from './src/table/tr.directive';
2121
export * from './src/table/tr-expand.directive';
2222
export * from './src/table/title-footer.component';

components/table/src/table-style.service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import { map } from 'rxjs/operators';
1010
import { NzSafeAny } from 'ng-zorro-antd/core/types';
1111

1212
import { NzThMeasureDirective } from './cell/th-measure.directive';
13+
import { NzTableSummaryFixedType } from './table.types';
1314

1415
@Injectable()
1516
export class NzTableStyleService {
1617
theadTemplate$ = new ReplaySubject<TemplateRef<NzSafeAny>>(1);
18+
tfootTemplate$ = new ReplaySubject<TemplateRef<NzSafeAny>>(1);
19+
tfootFixed$ = new ReplaySubject<NzTableSummaryFixedType | null>(1);
1720
hasFixLeft$ = new ReplaySubject<boolean>(1);
1821
hasFixRight$ = new ReplaySubject<boolean>(1);
1922
hostWidth$ = new ReplaySubject<number>(1);
@@ -54,6 +57,14 @@ export class NzTableStyleService {
5457
this.theadTemplate$.next(template);
5558
}
5659

60+
setTfootTemplate(template: TemplateRef<NzSafeAny>): void {
61+
this.tfootTemplate$.next(template);
62+
}
63+
64+
setTfootFixed(fixed: NzTableSummaryFixedType | null): void {
65+
this.tfootFixed$.next(fixed);
66+
}
67+
5768
setHasFixLeft(hasFixLeft: boolean): void {
5869
this.hasFixLeft$.next(hasFixLeft);
5970
}
@@ -106,6 +117,4 @@ export class NzTableStyleService {
106117
}
107118
this.enableAutoMeasure$.next(enableAutoMeasure);
108119
}
109-
110-
constructor() {}
111120
}

components/table/src/table.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { NzTableInnerScrollComponent } from './table/table-inner-scroll.componen
2828
import { NzTableVirtualScrollDirective } from './table/table-virtual-scroll.directive';
2929
import { NzTableComponent } from './table/table.component';
3030
import { NzTbodyComponent } from './table/tbody.component';
31-
import { NzTfootSummaryDirective } from './table/tfoot-summary.directive';
31+
import { NzTfootSummaryComponent } from './table/tfoot-summary.component';
3232
import { NzTheadComponent } from './table/thead.component';
3333
import { NzTableTitleFooterComponent } from './table/title-footer.component';
3434
import { NzTrExpandDirective } from './table/tr-expand.directive';
@@ -46,7 +46,7 @@ import { NzTrDirective } from './table/tr.directive';
4646
NzTbodyComponent,
4747
NzTrDirective,
4848
NzTrExpandDirective,
49-
NzTfootSummaryDirective,
49+
NzTfootSummaryComponent,
5050
NzTableVirtualScrollDirective,
5151
NzCellFixedDirective,
5252
NzCustomColumnDirective,
@@ -81,7 +81,7 @@ import { NzTrDirective } from './table/tr.directive';
8181
NzCustomColumnDirective,
8282
NzFilterTriggerComponent,
8383
NzTrExpandDirective,
84-
NzTfootSummaryDirective,
84+
NzTfootSummaryComponent,
8585
NzCellBreakWordDirective,
8686
NzCellAlignDirective,
8787
NzCellEllipsisDirective,

components/table/src/table.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ export interface NzCustomColumn {
2828
width: number;
2929
fixWidth?: boolean;
3030
}
31+
32+
export type NzTableSummaryFixedType = 'top' | 'bottom';

components/table/src/table/table-content.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import { NzTableLayout } from '../table.types';
2525
}
2626
<ng-template [ngTemplateOutlet]="contentTemplate"></ng-template>
2727
<ng-content></ng-content>
28+
@if (tfootTemplate) {
29+
<tfoot class="ant-table-summary">
30+
<ng-template [ngTemplateOutlet]="tfootTemplate"></ng-template>
31+
</tfoot>
32+
}
2833
`,
2934
host: {
3035
'[style.table-layout]': 'tableLayout',
@@ -39,6 +44,7 @@ export class NzTableContentComponent {
3944
@Input() tableLayout: NzTableLayout = 'auto';
4045
@Input() theadTemplate: TemplateRef<NzSafeAny> | null = null;
4146
@Input() contentTemplate: TemplateRef<NzSafeAny> | null = null;
47+
@Input() tfootTemplate: TemplateRef<NzSafeAny> | null = null;
4248
@Input() listOfColWidth: ReadonlyArray<string | null> = [];
4349
@Input() scrollX: string | null = null;
4450
}

components/table/src/table/table-fixed-row.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,26 @@ export class NzTableFixedRowComponent implements OnInit, OnDestroy, AfterViewIni
5050
hostWidth$ = new BehaviorSubject<number | null>(null);
5151
enableAutoMeasure$ = new BehaviorSubject<boolean>(false);
5252
private destroy$ = new Subject<boolean>();
53+
5354
constructor(
5455
private nzTableStyleService: NzTableStyleService,
5556
private renderer: Renderer2
5657
) {}
58+
5759
ngOnInit(): void {
5860
if (this.nzTableStyleService) {
5961
const { enableAutoMeasure$, hostWidth$ } = this.nzTableStyleService;
6062
enableAutoMeasure$.pipe(takeUntil(this.destroy$)).subscribe(this.enableAutoMeasure$);
6163
hostWidth$.pipe(takeUntil(this.destroy$)).subscribe(this.hostWidth$);
6264
}
6365
}
66+
6467
ngAfterViewInit(): void {
6568
this.nzTableStyleService.columnCount$.pipe(takeUntil(this.destroy$)).subscribe(count => {
6669
this.renderer.setAttribute(this.tdElement.nativeElement, 'colspan', `${count}`);
6770
});
6871
}
72+
6973
ngOnDestroy(): void {
7074
this.destroy$.next(true);
7175
this.destroy$.complete();

0 commit comments

Comments
 (0)