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

Commit

Permalink
Fix bug ExpandMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Feb 6, 2018
1 parent 23b2da7 commit b05befd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/datas/hierarchical-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ export const HierarchicalCountries = [
name: 'Angola',
capital: 'Luanda',
phone: '244',
currency: 'AOA'
currency: 'AOA',
children: [
{
id: 'TT',
name: 'Test',
capital: 'Luanda',
phone: '244',
currency: 'AOA',
children: [
{
id: 'TU',
name: 'Test2',
capital: 'Luanda',
phone: '244',
currency: 'AOA'
}]
}]
},
{
id: 'BF',
Expand Down
14 changes: 14 additions & 0 deletions src/ngx-tree-select/src/services/select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ 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 Down Expand Up @@ -144,6 +155,9 @@ export class SelectService {
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 {
Expand Down

0 comments on commit b05befd

Please sign in to comment.