Added Input Values can control checkbox with node click.

pull/14298/head
Fatih KILIÇ 3 years ago
parent 6bfef48305
commit 691a02c46a

@ -3,6 +3,7 @@ import {
ContentChild, ContentChild,
EventEmitter, EventEmitter,
Input, Input,
OnChanges,
Output, Output,
TemplateRef, TemplateRef,
ViewEncapsulation, ViewEncapsulation,
@ -24,7 +25,7 @@ export type DropEvent = NzFormatEmitEvent & { pos: number };
], ],
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
}) })
export class TreeComponent { export class TreeComponent implements OnChanges {
dropPosition: number; dropPosition: number;
dropdowns = {} as { [key: string]: NgbDropdown }; dropdowns = {} as { [key: string]: NgbDropdown };
@ -44,19 +45,31 @@ export class TreeComponent {
@Input() nodes = []; @Input() nodes = [];
@Input() expandedKeys: string[] = []; @Input() expandedKeys: string[] = [];
@Input() selectedNode: any; @Input() selectedNode: any;
@Input() changeCheckboxWithNode: boolean;
@Input() changedNodeValues = [];
@Input() isNodeSelected = node => this.selectedNode?.id === node.key; @Input() isNodeSelected = node => this.selectedNode?.id === node.key;
@Input() beforeDrop = (event: NzFormatBeforeDropEvent) => { @Input() beforeDrop = (event: NzFormatBeforeDropEvent) => {
this.dropPosition = event.pos; this.dropPosition = event.pos;
return of(false); return of(false);
}; };
ngOnChanges() {
this.checkedKeys = [...this.changedNodeValues];
}
onSelectedNodeChange(node) { onSelectedNodeChange(node) {
this.selectedNode = node.origin.entity; this.selectedNode = node.origin.entity;
if (this.changeCheckboxWithNode) {
this.selectedNodeChange.emit(node);
this.checkedKeys = [...this.changedNodeValues];
this.checkedKeysChange.emit(this.changedNodeValues);
} else {
this.selectedNodeChange.emit(node.origin.entity); this.selectedNodeChange.emit(node.origin.entity);
} }
}
onCheckboxChange(event) { onCheckboxChange(event) {
this.checkedKeys = [...event.keys]; this.checkedKeys = this.changedNodeValues = [...event.keys];
this.checkedKeysChange.emit(event.keys); this.checkedKeysChange.emit(event.keys);
} }

Loading…
Cancel
Save