diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index b85b2165bc9..597947d30fd 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -5327,6 +5327,8 @@ export class ColumnFilter implements AfterContentInit { overlayId: any; + applyHasBeenClicked: boolean = false; + get fieldConstraints(): FilterMetadata[] | undefined | null { return this.dt.filters ? this.dt.filters[this.field] : null; } @@ -5573,6 +5575,10 @@ export class ColumnFilter implements AfterContentInit { } onEscape() { + if (this.hasFilterNotBeenApplied()) { + this.clearFilter(); + } + this.applyHasBeenClicked = false; this.overlayVisible = false; this.icon?.nativeElement.focus(); } @@ -5673,6 +5679,10 @@ export class ColumnFilter implements AfterContentInit { return false; } + hasFilterNotBeenApplied(): boolean { + return this.hasFilter() && !this.applyHasBeenClicked; + } + isOutsideClicked(event: any): boolean { return !( DomHandler.hasClass(this.overlay?.nextElementSibling, 'p-overlay') || @@ -5747,6 +5757,10 @@ export class ColumnFilter implements AfterContentInit { } hide() { + if (this.hasFilterNotBeenApplied()) { + this.clearFilter(); + } + this.applyHasBeenClicked = false; this.overlayVisible = false; this.cd.markForCheck(); } @@ -5759,12 +5773,14 @@ export class ColumnFilter implements AfterContentInit { } clearFilter() { + this.applyHasBeenClicked = false; this.initFieldFilterConstraint(); this.dt._filter(); if (this.hideOnClear) this.hide(); } applyFilter() { + this.applyHasBeenClicked = true; this.dt._filter(); this.hide(); }