Skip to content

Commit

Permalink
Merge pull request primefaces#15594 from RogueTea/table-clear-filters
Browse files Browse the repository at this point in the history
Table: clear filter when dirty but not applied
  • Loading branch information
cetincakiroglu authored May 30, 2024
2 parents 8008a84 + d00f2bf commit 70ac706
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,6 +5327,8 @@ export class ColumnFilter implements AfterContentInit {

overlayId: any;

applyHasBeenClicked: boolean = false;

get fieldConstraints(): FilterMetadata[] | undefined | null {
return this.dt.filters ? <FilterMetadata[]>this.dt.filters[<string>this.field] : null;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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') ||
Expand Down Expand Up @@ -5747,6 +5757,10 @@ export class ColumnFilter implements AfterContentInit {
}

hide() {
if (this.hasFilterNotBeenApplied()) {
this.clearFilter();
}
this.applyHasBeenClicked = false;
this.overlayVisible = false;
this.cd.markForCheck();
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 70ac706

Please sign in to comment.