Skip to content

Commit 1507ed0

Browse files
authored
feat(module:table): nzExpand supports custom icon (#7886)
1 parent a9dc205 commit 1507ed0

File tree

6 files changed

+114
-7
lines changed

6 files changed

+114
-7
lines changed

components/table/demo/colspan-rowspan.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
order: 14
2+
order: 15
33
title:
44
en-US: colSpan and rowSpan
55
zh-CN: 表格行/列合并

components/table/demo/expand-icon.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
order: 14
3+
title:
4+
en-US: Customize the expansion icon
5+
zh-CN: 自定义展开 icon
6+
---
7+
8+
## zh-CN
9+
10+
当使用 `nzExpand` 属性时,添加 `nzExpandIcon` 自定义展开图标。
11+
12+
## en-US
13+
14+
When using the `nzExpand` prop, add the `nzExpandIcon` custom expand icon.
15+
16+

components/table/demo/expand-icon.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-table-expand-icon',
5+
template: `
6+
<nz-table #nzTable [nzData]="listOfData" nzTableLayout="fixed">
7+
<thead>
8+
<tr>
9+
<th nzWidth="60px"></th>
10+
<th>Name</th>
11+
<th>Age</th>
12+
<th>Address</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<ng-container *ngFor="let data of nzTable.data">
17+
<tr>
18+
<td [nzExpand]="expandSet.has(data.id)" [nzExpandIcon]="expandIcon"></td>
19+
<td>{{ data.name }}</td>
20+
<td>{{ data.age }}</td>
21+
<td>{{ data.address }}</td>
22+
</tr>
23+
<tr [nzExpand]="expandSet.has(data.id)">
24+
<span>{{ data.description }}</span>
25+
</tr>
26+
<ng-template #expandIcon>
27+
<span
28+
nz-icon
29+
*ngIf="!expandSet.has(data.id)"
30+
nzType="plus-circle"
31+
nzTheme="outline"
32+
(click)="onExpandChange(data.id, true)"
33+
></span>
34+
<span
35+
nz-icon
36+
*ngIf="expandSet.has(data.id)"
37+
nzType="minus-circle"
38+
nzTheme="outline"
39+
(click)="onExpandChange(data.id, false)"
40+
></span>
41+
</ng-template>
42+
</ng-container>
43+
</tbody>
44+
</nz-table>
45+
`
46+
})
47+
export class NzDemoTableExpandIconComponent {
48+
expandSet = new Set<number>();
49+
onExpandChange(id: number, checked: boolean): void {
50+
if (checked) {
51+
this.expandSet.add(id);
52+
} else {
53+
this.expandSet.delete(id);
54+
}
55+
}
56+
listOfData = [
57+
{
58+
id: 1,
59+
name: 'John Brown',
60+
age: 32,
61+
expand: false,
62+
address: 'New York No. 1 Lake Park',
63+
description: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.'
64+
},
65+
{
66+
id: 2,
67+
name: 'Jim Green',
68+
age: 42,
69+
expand: false,
70+
address: 'London No. 1 Lake Park',
71+
description: 'My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park.'
72+
},
73+
{
74+
id: 3,
75+
name: 'Joe Black',
76+
age: 32,
77+
expand: false,
78+
address: 'Sidney No. 1 Lake Park',
79+
description: 'My name is Joe Black, I am 32 years old, living in Sidney No. 1 Lake Park.'
80+
}
81+
];
82+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Expand property
184184
| -------- | ----------- | ---- | ------- |
185185
| `[nzShowExpand]` | Whether show expand icon | `boolean` | - |
186186
| `[nzExpand]` | Current expand status, double binding | `boolean` | - |
187+
| `[nzExpandIcon]` | Custom expand icon | `TemplateRef<void>` | - |
187188
| `(nzExpandChange)` | Expand status change callback | `EventEmitter<boolean>` | - |
188189

189190
Style property

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

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Table 组件同时具备了易用性和高度可定制性
184184
| --- | --- | --- | --- |
185185
| `[nzShowExpand]` | 是否显示展开按钮 | `boolean` | - |
186186
| `[nzExpand]` | 当前展开按钮状态,可双向绑定 | `boolean` | - |
187+
| `[nzExpandIcon]` | 自定义展开图标 | `TemplateRef<void>` | - |
187188
| `(nzExpandChange)` | 当前展开按钮状态改变回调函数 | `EventEmitter<boolean>` | - |
188189

189190
样式属性

components/table/src/cell/td-addon.component.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Output,
1515
SimpleChange,
1616
SimpleChanges,
17+
TemplateRef,
1718
ViewEncapsulation
1819
} from '@angular/core';
1920

@@ -29,12 +30,17 @@ import { InputBoolean } from 'ng-zorro-antd/core/util';
2930
template: `
3031
<ng-container *ngIf="nzShowExpand || nzIndentSize > 0">
3132
<nz-row-indent [indentSize]="nzIndentSize"></nz-row-indent>
32-
<button
33-
nz-row-expand-button
34-
[expand]="nzExpand"
35-
(expandChange)="onExpandChange($event)"
36-
[spaceMode]="!nzShowExpand"
37-
></button>
33+
<ng-template #rowExpand>
34+
<button
35+
nz-row-expand-button
36+
[expand]="nzExpand"
37+
(expandChange)="onExpandChange($event)"
38+
[spaceMode]="!nzShowExpand"
39+
></button>
40+
</ng-template>
41+
<ng-container *ngIf="nzExpandIcon; else rowExpand">
42+
<ng-template [ngTemplateOutlet]="nzExpandIcon"></ng-template>
43+
</ng-container>
3844
</ng-container>
3945
<label
4046
nz-checkbox
@@ -63,6 +69,7 @@ export class NzTdAddOnComponent implements OnChanges {
6369
@Input() @InputBoolean() nzShowExpand = false;
6470
@Input() @InputBoolean() nzShowCheckbox = false;
6571
@Input() @InputBoolean() nzExpand = false;
72+
@Input() nzExpandIcon: TemplateRef<void> | null = null;
6673
@Output() readonly nzCheckedChange = new EventEmitter<boolean>();
6774
@Output() readonly nzExpandChange = new EventEmitter<boolean>();
6875
private isNzShowExpandChanged = false;

0 commit comments

Comments
 (0)