Skip to content

Commit 20bb5b2

Browse files
LafferyElderJames
andauthored
feat(module:table): support nzSummary (#8639)
* feat(module: table): add summary * Update tr.directive.ts * tfoot-summary.directive.ts support standalone * feat(module: table): add tests for nzSummary * chore: fix build error --------- Co-authored-by: ElderJames <shunjiey@hotmail.com>
1 parent 13e8a45 commit 20bb5b2

File tree

11 files changed

+189
-5
lines changed

11 files changed

+189
-5
lines changed

components/table/demo/module

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { NzIconModule } from 'ng-zorro-antd/icon';
1111
import { NzModalModule } from 'ng-zorro-antd/modal';
1212
import { NzGridModule } from 'ng-zorro-antd/grid';
1313
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
14+
import { NzTypographyModule } from 'ng-zorro-antd/typography';
1415

1516
export const moduleList = [
1617
NzTableModule,
@@ -25,5 +26,6 @@ export const moduleList = [
2526
NzButtonModule,
2627
NzInputModule,
2728
NzIconModule,
28-
NzPopconfirmModule
29+
NzPopconfirmModule,
30+
NzTypographyModule
2931
];

components/table/demo/summary.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 29
3+
title:
4+
en-US: Summary
5+
zh-CN: 总结栏
6+
---
7+
8+
## zh-CN
9+
10+
通过 `nzSummary` 设置总结栏。
11+
12+
## en-US
13+
14+
Set summary content by `nzSummary` prop.

components/table/demo/summary.ts

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-table-summary',
5+
template: `
6+
<nz-table #middleTable nzBordered [nzData]="data" [nzShowPagination]="false">
7+
<thead>
8+
<tr>
9+
<th>Name</th>
10+
<th>Borrow</th>
11+
<th>Repayment</th>
12+
</tr>
13+
</thead>
14+
<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>
21+
</tbody>
22+
<tfoot nzSummary>
23+
<tr>
24+
<td>Total</td>
25+
<td>
26+
<span nz-typography nzType="danger">{{ totalBorrow }}</span>
27+
</td>
28+
<td>
29+
<span nz-typography>{{ totalRepayment }}</span>
30+
</td>
31+
</tr>
32+
<tr>
33+
<td>Balance</td>
34+
<td colspan="2">
35+
<span nz-typography>{{ totalBorrow - totalRepayment }}</span>
36+
</td>
37+
</tr>
38+
</tfoot>
39+
</nz-table>
40+
`,
41+
styles: [
42+
`
43+
tfoot th,
44+
tfoot td {
45+
background: #fafafa;
46+
}
47+
`
48+
]
49+
})
50+
export class NzDemoTableSummaryComponent implements OnInit {
51+
data = [
52+
{
53+
name: 'John Brown',
54+
borrow: 10,
55+
repayment: 33
56+
},
57+
{
58+
name: 'Jim Green',
59+
borrow: 100,
60+
repayment: 0
61+
},
62+
{
63+
name: 'Joe Black',
64+
borrow: 10,
65+
repayment: 10
66+
},
67+
{
68+
name: 'Jim Red',
69+
borrow: 75,
70+
repayment: 45
71+
}
72+
];
73+
74+
fixedData: Array<{ name: string; description: string }> = [];
75+
totalBorrow = 0;
76+
totalRepayment = 0;
77+
ngOnInit(): void {
78+
this.data.forEach(({ borrow, repayment }) => {
79+
this.totalBorrow += borrow;
80+
this.totalRepayment += repayment;
81+
});
82+
}
83+
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ Other property
216216
| ------------ | -------------------------------------------------------- | --------- | ------- |
217217
| `[nzExpand]` | Whether expand current row,used with `nzExpand` of `td` | `boolean` | - |
218218

219+
### tfoot
220+
221+
| Property | Description | Type | Default |
222+
| -------- | ----------- | ---- | ------- |
223+
| `[nzSummary]` | Summary content | `boolean` | - |
224+
219225
### nz-filter-trigger:standalone
220226

221227
Customized filter panel

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

+6
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ Table 组件同时具备了易用性和高度可定制性
217217
| ------------ | ---------------------------------------------------- | --------- | ------ |
218218
| `[nzExpand]` | 当前列是否展开,与 `td` 上的 `nzExpand` 属性配合使用 | `boolean` | - |
219219

220+
### tfoot
221+
222+
| 参数 | 说明 | 类型 | 默认值 |
223+
| ------------ | ---------------------------------------------------- | --------- | ------ |
224+
| `[nzSummary]` | 总结栏 | `boolean` | - |
225+
220226
### nz-filter-trigger:standalone
221227

222228
用于自定义筛选功能

components/table/public-api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +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';
1920
export * from './src/table/tr.directive';
2021
export * from './src/table/tr-expand.directive';
2122
export * from './src/table/title-footer.component';

components/table/src/table.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +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';
3132
import { NzTheadComponent } from './table/thead.component';
3233
import { NzTableTitleFooterComponent } from './table/title-footer.component';
3334
import { NzTrExpandDirective } from './table/tr-expand.directive';
@@ -45,6 +46,7 @@ import { NzTrDirective } from './table/tr.directive';
4546
NzTbodyComponent,
4647
NzTrDirective,
4748
NzTrExpandDirective,
49+
NzTfootSummaryDirective,
4850
NzTableVirtualScrollDirective,
4951
NzCellFixedDirective,
5052
NzCustomColumnDirective,
@@ -79,6 +81,7 @@ import { NzTrDirective } from './table/tr.directive';
7981
NzCustomColumnDirective,
8082
NzFilterTriggerComponent,
8183
NzTrExpandDirective,
84+
NzTfootSummaryDirective,
8285
NzCellBreakWordDirective,
8386
NzCellAlignDirective,
8487
NzCellEllipsisDirective,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Use of this source code is governed by an MIT-style license that can be
3+
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
4+
*/
5+
6+
import { Directive } from '@angular/core';
7+
8+
@Directive({
9+
selector: 'tfoot[nzSummary]',
10+
host: {
11+
class: 'ant-table-summary'
12+
},
13+
standalone: true
14+
})
15+
export class NzTfootSummaryDirective {}

components/table/src/table/tr.directive.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import { map, mergeMap, startWith, switchMap, takeUntil } from 'rxjs/operators';
1010
import { NzCellFixedDirective } from '../cell/cell-fixed.directive';
1111
import { NzThMeasureDirective } from '../cell/th-measure.directive';
1212
import { NzTableStyleService } from '../table-style.service';
13+
import { NzTfootSummaryDirective } from './tfoot-summary.directive';
1314

1415
@Directive({
1516
selector:
1617
'tr:not([mat-row]):not([mat-header-row]):not([nz-table-measure-row]):not([nzExpand]):not([nz-table-fixed-row])',
1718
host: {
18-
'[class.ant-table-row]': 'isInsideTable'
19+
'[class.ant-table-row]': 'isInsideTable && !isInsideSummaryTfoot'
1920
},
2021
standalone: true
2122
})
@@ -49,7 +50,9 @@ export class NzTrDirective implements AfterContentInit, OnDestroy {
4950
);
5051

5152
private nzTableStyleService = inject(NzTableStyleService, { optional: true });
53+
private nzTfootSummaryDirective = inject(NzTfootSummaryDirective, { optional: true });
5254
isInsideTable = !!this.nzTableStyleService;
55+
isInsideSummaryTfoot = !!this.nzTfootSummaryDirective;
5356

5457
ngAfterContentInit(): void {
5558
if (this.nzTableStyleService) {
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Component, DebugElement } from '@angular/core';
2+
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
4+
5+
import { NzTableModule } from '../table.module';
6+
import { NzTfootSummaryDirective } from '../table/tfoot-summary.directive';
7+
8+
describe('nz-foot', () => {
9+
beforeEach(fakeAsync(() => {
10+
TestBed.configureTestingModule({
11+
imports: [NzTableModule],
12+
declarations: [TestComponent]
13+
});
14+
TestBed.compileComponents();
15+
}));
16+
17+
describe('nz-foot in nz-table', () => {
18+
let fixture: ComponentFixture<TestComponent>;
19+
let tfoot: DebugElement;
20+
21+
beforeEach(() => {
22+
fixture = TestBed.createComponent(TestComponent);
23+
fixture.detectChanges();
24+
tfoot = fixture.debugElement.query(By.directive(NzTfootSummaryDirective));
25+
});
26+
27+
it('should nzSummary work ', () => {
28+
fixture.detectChanges();
29+
expect(tfoot.nativeElement.classList).toContain('ant-table-summary');
30+
});
31+
});
32+
});
33+
34+
@Component({
35+
template: `
36+
<nz-table>
37+
<thead>
38+
<th></th>
39+
<th></th>
40+
</thead>
41+
<tbody>
42+
<tr>
43+
<td>1</td>
44+
<td>2</td>
45+
</tr>
46+
</tbody>
47+
<tfoot nzSummary>
48+
<td colspan="2">summary</td>
49+
<tfoot> </tfoot></tfoot
50+
></nz-table>
51+
`
52+
})
53+
export class TestComponent {}

scripts/site/_site/doc/app/online-ide/online-ide.service.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { DOCUMENT } from '@angular/common';
2-
import { Injectable, inject } from '@angular/core';
1+
import { Injectable } from '@angular/core';
32

43
import sdk from '@stackblitz/sdk';
54
import { VERSION } from 'ng-zorro-antd/version';
@@ -15,7 +14,6 @@ import polyfillTS from './files/polyfill';
1514
providedIn: 'root'
1615
})
1716
export class OnlineIdeService {
18-
private document: Document = inject(DOCUMENT);
1917
template = 'angular-cli' as const;
2018
dependencies = {
2119
'@angular/animations': '^18.0.0',

0 commit comments

Comments
 (0)