Browse Source

fix abp tree value update

pull/14675/head
muhammedaltug 4 years ago
parent
commit
2bede22f7e
  1. 17
      npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts

17
npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts

@ -3,12 +3,11 @@ import {
ContentChild, ContentChild,
EventEmitter, EventEmitter,
Input, Input,
OnChanges,
Output, Output,
TemplateRef, TemplateRef,
ViewEncapsulation, ViewEncapsulation,
} from '@angular/core'; } from '@angular/core';
import { NzFormatEmitEvent, NzFormatBeforeDropEvent } from 'ng-zorro-antd/tree'; import { NzFormatBeforeDropEvent, NzFormatEmitEvent } from 'ng-zorro-antd/tree';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { TreeNodeTemplateDirective } from '../templates/tree-node-template.directive'; import { TreeNodeTemplateDirective } from '../templates/tree-node-template.directive';
import { ExpandedIconTemplateDirective } from '../templates/expanded-icon-template.directive'; import { ExpandedIconTemplateDirective } from '../templates/expanded-icon-template.directive';
@ -25,7 +24,7 @@ export type DropEvent = NzFormatEmitEvent & { pos: number };
], ],
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
}) })
export class TreeComponent implements OnChanges { export class TreeComponent {
dropPosition: number; dropPosition: number;
dropdowns = {} as { [key: string]: NgbDropdown }; dropdowns = {} as { [key: string]: NgbDropdown };
@ -46,30 +45,26 @@ export class TreeComponent implements OnChanges {
@Input() expandedKeys: string[] = []; @Input() expandedKeys: string[] = [];
@Input() selectedNode: any; @Input() selectedNode: any;
@Input() changeCheckboxWithNode: boolean; @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) { if (this.changeCheckboxWithNode) {
this.selectedNodeChange.emit(node); this.selectedNodeChange.emit(node);
this.checkedKeys = [...this.changedNodeValues]; const newVal = [...this.checkedKeys, node.key];
this.checkedKeysChange.emit(this.changedNodeValues); this.checkedKeys = newVal;
this.checkedKeysChange.emit(newVal);
} else { } else {
this.selectedNodeChange.emit(node.origin.entity); this.selectedNodeChange.emit(node.origin.entity);
} }
} }
onCheckboxChange(event) { onCheckboxChange(event) {
this.checkedKeys = this.changedNodeValues = [...event.keys]; this.checkedKeys = [...event.keys];
this.checkedKeysChange.emit(event.keys); this.checkedKeysChange.emit(event.keys);
} }

Loading…
Cancel
Save