Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
fix: tree select expandMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Feb 9, 2018
1 parent eb68c2c commit 586c71b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
6 changes: 1 addition & 5 deletions src/ngx-tree-select/src/components/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class TreeSelectComponent implements ControlValueAccessor {
for (const item of this.internalItems) {
this.ProcessMatchFilterTreeItem(item, this.svc.Configuration.filter);
}
this.svc.setExpand();
}

public constructor(
Expand Down Expand Up @@ -268,11 +269,6 @@ export class TreeSelectComponent implements ControlValueAccessor {
tree.text.toLowerCase().indexOf(filter.toLowerCase()) > -1 ||
result
);
if (filter !== '') {
tree.isOpen = true;
} else {
tree.isOpen = false;
}
return tree.matchFilter;
}
}
9 changes: 9 additions & 0 deletions src/ngx-tree-select/src/models/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export class SelectOption {
return this.childProperty && this.childProperty.trim().length > 0;
}

public get filterExpandMode(): ExpandMode
{
if (this.filter !== '') {
return ExpandMode.All;
} else {
return this.expandMode;
}
}

public displayCheckbox(): boolean {
return this.allowMultiple && this.isHierarchy();
}
Expand Down
37 changes: 15 additions & 22 deletions src/ngx-tree-select/src/services/select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,6 @@ export class SelectService {
}
}

public setAllOpoen(items: SelectableItem[]) {
for (const itm of items) {
if (itm.hasChild) {
itm.isOpen = true;
this.setAllOpoen(itm.children);
} else {
itm.isOpen = true;
}
}
}

public setConfiguration(delegate: OptionDelegate, processItems: boolean): void {
const modelBck = this._options.model;
delegate(this._options);
Expand All @@ -151,17 +140,21 @@ export class SelectService {
}

public setExpand() {
if (this._items) {
for (const item of this._items) {
if (this._options.expandMode === ExpandMode.All) {
item.isOpen = true;
if (item.hasChild) {
this.setAllOpoen(item.children);
}
} else if (this._options.expandMode === ExpandMode.Selection && item.children) {
item.isOpen = item.children.some((itm: SelectableItem) => itm.isOpen || itm.selected);
} else {
item.isOpen = false;
this.setExpandForList(this._items);
}

private setExpandForList(items: SelectableItem[]) {
if (!items) {
return;
}
for (const item of items) {
this.setExpandForList(item.children);
item.isOpen = (this._options.filterExpandMode === ExpandMode.All);
if (this._options.filterExpandMode === ExpandMode.Selection) {
if (item.children) {
item.isOpen = item.children.some(
(itm: SelectableItem) => itm.isOpen || itm.selected
);
}
}
}
Expand Down

0 comments on commit 586c71b

Please sign in to comment.