-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:transfer): add nzShowSelectAll & nzRenderList properties (#…
- Loading branch information
Showing
12 changed files
with
378 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 5 | ||
title: | ||
zh-CN: 表格穿梭框 | ||
en-US: Table Transfer | ||
--- | ||
|
||
## zh-CN | ||
|
||
使用 Table 组件作为自定义渲染列表。 | ||
|
||
## en-US | ||
|
||
Customize render list with Table component. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { TransferItem } from 'ng-zorro-antd/transfer'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-transfer-table-transfer', | ||
template: ` | ||
<nz-transfer | ||
[nzDataSource]="list" | ||
[nzDisabled]="disabled" | ||
[nzShowSearch]="showSearch" | ||
[nzShowSelectAll]="false" | ||
[nzRenderList]="[renderList, renderList]" | ||
(nzSelectChange)="select($event)" | ||
(nzChange)="change($event)" | ||
> | ||
<ng-template | ||
#renderList | ||
let-items | ||
let-direction="direction" | ||
let-stat="stat" | ||
let-disabled="disabled" | ||
let-onItemSelectAll="onItemSelectAll" | ||
let-onItemSelect="onItemSelect" | ||
> | ||
<nz-table #t [nzData]="convertItems(items)" nzSize="small"> | ||
<thead> | ||
<tr> | ||
<th | ||
nzShowCheckbox | ||
[nzDisabled]="disabled" | ||
[nzChecked]="stat.checkAll" | ||
[nzIndeterminate]="stat.checkHalf" | ||
(nzCheckedChange)="onItemSelectAll($event)" | ||
></th> | ||
<th>Name</th> | ||
<th *ngIf="direction === 'left'">Tag</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let data of t.data" (click)="onItemSelect(data)"> | ||
<td | ||
nzShowCheckbox | ||
[nzChecked]="data.checked" | ||
[nzDisabled]="disabled || data.disabled" | ||
(nzCheckedChange)="onItemSelect(data)" | ||
></td> | ||
<td>{{ data.title }}</td> | ||
<td *ngIf="direction === 'left'"> | ||
<nz-tag>{{ data.tag }}</nz-tag> | ||
</td> | ||
<td>{{ data.description }}</td> | ||
</tr> | ||
</tbody> | ||
</nz-table> | ||
</ng-template> | ||
</nz-transfer> | ||
<div style="margin-top: 8px;"> | ||
<nz-switch [(ngModel)]="disabled" nzCheckedChildren="disabled" nzUnCheckedChildren="disabled"></nz-switch> | ||
<nz-switch [(ngModel)]="showSearch" nzCheckedChildren="showSearch" nzUnCheckedChildren="showSearch"></nz-switch> | ||
</div> | ||
` | ||
}) | ||
export class NzDemoTransferTableTransferComponent implements OnInit { | ||
// tslint:disable-next-line:no-any | ||
list: any[] = []; | ||
disabled = false; | ||
showSearch = false; | ||
|
||
ngOnInit(): void { | ||
for (let i = 0; i < 20; i++) { | ||
this.list.push({ | ||
key: i.toString(), | ||
title: `content${i + 1}`, | ||
description: `description of content${i + 1}`, | ||
disabled: i % 4 === 0, | ||
tag: ['cat', 'dog', 'bird'][i % 3] | ||
}); | ||
} | ||
|
||
[2, 3].forEach(idx => (this.list[idx].direction = 'right')); | ||
} | ||
|
||
convertItems(items: TransferItem[]): TransferItem[] { | ||
return items.filter(i => !i.hide); | ||
} | ||
|
||
select(ret: {}): void { | ||
console.log('nzSelectChange', ret); | ||
} | ||
|
||
change(ret: {}): void { | ||
console.log('nzChange', ret); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 6 | ||
title: | ||
zh-CN: 树穿梭框 | ||
en-US: Tree Transfer | ||
--- | ||
|
||
## zh-CN | ||
|
||
使用 Tree 组件作为自定义渲染列表。 | ||
|
||
## en-US | ||
|
||
Customize render list with Tree component. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// tslint:disable: no-any | ||
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core'; | ||
import { NzTreeNode } from 'ng-zorro-antd/core'; | ||
import { TransferChange, TransferItem } from 'ng-zorro-antd/transfer'; | ||
import { NzTreeComponent } from 'ng-zorro-antd/tree'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-transfer-tree-transfer', | ||
template: ` | ||
<nz-transfer | ||
[nzDataSource]="list" | ||
[nzShowSelectAll]="false" | ||
[nzRenderList]="[leftRenderList, null]" | ||
(nzChange)="change($event)" | ||
> | ||
<ng-template #leftRenderList let-items let-onItemSelectAll="onItemSelectAll" let-onItemSelect="onItemSelect"> | ||
<nz-tree #tree [nzData]="treeData" nzExpandAll nzBlockNode> | ||
<ng-template #nzTreeTemplate let-node> | ||
<span | ||
class="ant-tree-checkbox" | ||
[class.ant-tree-checkbox-disabled]="node.isDisabled" | ||
[class.ant-tree-checkbox-checked]="node.isChecked" | ||
(click)="checkBoxChange(node, onItemSelect)" | ||
> | ||
<span class="ant-tree-checkbox-inner"></span> | ||
</span> | ||
<span | ||
(click)="checkBoxChange(node, onItemSelect)" | ||
class="ant-tree-node-content-wrapper ant-tree-node-content-wrapper-open" | ||
>{{ node.title }}</span | ||
> | ||
</ng-template> | ||
</nz-tree> | ||
</ng-template> | ||
</nz-transfer> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class NzDemoTransferTreeTransferComponent { | ||
@ViewChild('tree', { static: true }) tree: NzTreeComponent; | ||
list: any[] = [ | ||
{ id: 1, parentid: 0, title: 'parent 1' }, | ||
{ id: 2, parentid: 1, title: 'leaf 1-1', disabled: true, isLeaf: true }, | ||
{ id: 3, parentid: 1, title: 'leaf 1-2', isLeaf: true } | ||
]; | ||
treeData = this.generateTree(this.list); | ||
checkedNodeList: NzTreeNode[] = []; | ||
|
||
private generateTree(arr: TransferItem[]): TransferItem[] { | ||
const tree: TransferItem[] = []; | ||
const mappedArr: any = {}; | ||
let arrElem: TransferItem; | ||
let mappedElem: TransferItem; | ||
|
||
for (let i = 0, len = arr.length; i < len; i++) { | ||
arrElem = arr[i]; | ||
mappedArr[arrElem.id] = { ...arrElem }; | ||
mappedArr[arrElem.id].children = []; | ||
} | ||
|
||
for (const id in mappedArr) { | ||
if (mappedArr.hasOwnProperty(id)) { | ||
mappedElem = mappedArr[id]; | ||
if (mappedElem.parentid) { | ||
mappedArr[mappedElem.parentid].children.push(mappedElem); | ||
} else { | ||
tree.push(mappedElem); | ||
} | ||
} | ||
} | ||
return tree; | ||
} | ||
|
||
checkBoxChange(node: NzTreeNode, onItemSelect: (item: TransferItem) => void): void { | ||
if (node.isDisabled) { | ||
return; | ||
} | ||
node.isChecked = !node.isChecked; | ||
if (node.isChecked) { | ||
this.checkedNodeList.push(node); | ||
} else { | ||
const idx = this.checkedNodeList.indexOf(node); | ||
if (idx !== -1) { | ||
this.checkedNodeList.splice(idx, 1); | ||
} | ||
} | ||
const item = this.list.find(w => w.id === node.origin.id); | ||
onItemSelect(item); | ||
} | ||
|
||
change(ret: TransferChange): void { | ||
const isDisabled = ret.to === 'right'; | ||
this.checkedNodeList.forEach(node => { | ||
node.isDisabled = isDisabled; | ||
node.isChecked = isDisabled; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.