From da92c4700cefed57df0e3efbc5f9463dea9eadf9 Mon Sep 17 00:00:00 2001 From: Maxim Balaganskiy Date: Fri, 7 Dec 2018 12:18:31 +1100 Subject: [PATCH] fix(filter): handle prepopulated filter lines --- src/elements/filter/filter.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/elements/filter/filter.ts b/src/elements/filter/filter.ts index 1e10a4d..72ce0ed 100644 --- a/src/elements/filter/filter.ts +++ b/src/elements/filter/filter.ts @@ -14,11 +14,6 @@ export class Filter { @au.children("text-filter-line,lookup-filter-line,date-filter-line,number-filter-line,select-filter-line,bool-filter-line") availableFilterLines: IFilterLine[]; - availableFilterLinesChanged() { - if (!this.lines.length) { - this.availableFilterLines.filter(x => x.element.hasAttribute("default")).forEach(x => this.add(x)); - } - } @au.bindable pageSizes: number[]; @@ -33,11 +28,23 @@ export class Filter { lock: boolean; attached() { - // this.itemsViewSlot = new au.ViewSlot(this.itemsCollection, true); - this.availableFilterLinesChanged(); + if (this.lines.length) { + // remove prepopulated filters and add back via adding filter elements + let lines = [...this.lines]; + this.lines.splice(0); + lines.forEach(x => { + let fl = this.availableFilterLines.find(l => l.name === x.name); + let newFilter = this.add(fl); + newFilter.operator = x.operator; + newFilter.value = x.value; + }); + } + else { + this.availableFilterLines.filter(x => x.element.hasAttribute("default")).forEach(x => this.add(x)); + } } - add(i: IFilterLine) { + add(i: IFilterLine): IFilterLine { let container = au.DOM.createElement("filter-line-container"); container.setAttribute("remove.delegate", "remove($event.detail.filterLine)"); if (this.lock) { @@ -57,6 +64,7 @@ export class Filter { // this.itemsViewSlot.add(view); this.lines.push(filterVm); au.fireEvent(this.element, "added"); + return filterVm; } remove(i: IFilterLine) {