Skip to content

Commit

Permalink
initial fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueTea committed Jun 7, 2024
1 parent d4d2d33 commit 8934a4d
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5397,6 +5397,8 @@ export class ColumnFilter implements AfterContentInit {

applyHasBeenClicked: boolean = false;

private appliedFilter: any;

get fieldConstraints(): FilterMetadata[] | undefined | null {
return this.dt.filters ? <FilterMetadata[]>this.dt.filters[<string>this.field] : null;
}
Expand Down Expand Up @@ -5653,6 +5655,9 @@ export class ColumnFilter implements AfterContentInit {
onEscape() {
if (this.hasFilterNotBeenApplied()) {
this.clearFilter();
if (this.appliedFilter !== null) {
this.dt.filters[<string>this.field] = this.appliedFilter;
}
}
this.applyHasBeenClicked = false;
this.overlayVisible = false;
Expand Down Expand Up @@ -5748,15 +5753,52 @@ export class ColumnFilter implements AfterContentInit {
hasFilter(): boolean {
let fieldFilter = this.dt.filters[<string>this.field];
if (fieldFilter) {
if (Array.isArray(fieldFilter)) return !this.dt.isFilterBlank((<FilterMetadata[]>fieldFilter)[0].value);
else return !this.dt.isFilterBlank(fieldFilter.value);
if (Array.isArray(fieldFilter)) {
if (this.dt.isFilterBlank((<FilterMetadata[]>fieldFilter)[0].value)) {
this.appliedFilter = null;
}
return !this.dt.isFilterBlank((<FilterMetadata[]>fieldFilter)[0].value);
} else {
if (this.dt.isFilterBlank(fieldFilter.value)) {
this.appliedFilter = null;
}
return !this.dt.isFilterBlank(fieldFilter.value);
}
}

return false;
}

hasFilterNotBeenApplied(): boolean {
return this.hasFilter() && !this.applyHasBeenClicked;
let currentFilters = this.dt.filters[<string>this.field];
let lastAppliedFilters = this.appliedFilter;

if (this.applyHasBeenClicked) {
return false;
}
return this.compareFilters(currentFilters, lastAppliedFilters);
}

compareFilters(currentFilters: any, appliedFilters: any): boolean {
if (appliedFilters === null) {
return true;
}
if (Array.isArray(currentFilters)) {
if (currentFilters.length !== appliedFilters.length) {
return true;
}
for (let i = 0; i < currentFilters.length; i++) {
if (currentFilters[i].value !== appliedFilters[i].value) {
return true;
}
}
} else {
if (currentFilters.value !== appliedFilters.value) {
return true;
}
}

return false;
}

isOutsideClicked(event: any): boolean {
Expand Down Expand Up @@ -5835,6 +5877,11 @@ export class ColumnFilter implements AfterContentInit {
hide() {
if (this.hasFilterNotBeenApplied()) {
this.clearFilter();
// apply the previous filter if the user has not clicked the apply button
if (this.appliedFilter !== null) {
this.dt.filters[<string>this.field] = this.appliedFilter;
this.dt._filter();
}
}
this.applyHasBeenClicked = false;
this.overlayVisible = false;
Expand All @@ -5856,6 +5903,8 @@ export class ColumnFilter implements AfterContentInit {
}

applyFilter() {
// deep copy of current applied filter
this.appliedFilter = JSON.parse(JSON.stringify(this.dt.filters[<string>this.field]));
this.applyHasBeenClicked = true;
this.dt._filter();
this.hide();
Expand Down

0 comments on commit 8934a4d

Please sign in to comment.