|
| 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 | +} |
0 commit comments