Skip to content

Commit

Permalink
Fixed #9570 - p-table reset() causes errors in filter value binding
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Feb 16, 2021
1 parent 21e9823 commit 979f95e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export class TableService {
private valueSource = new Subject<any>();
private totalRecordsSource = new Subject<any>();
private columnsSource = new Subject();
private resetSource = new Subject();

sortSource$ = this.sortSource.asObservable();
selectionSource$ = this.selectionSource.asObservable();
contextMenuSource$ = this.contextMenuSource.asObservable();
valueSource$ = this.valueSource.asObservable();
totalRecordsSource$ = this.totalRecordsSource.asObservable();
columnsSource$ = this.columnsSource.asObservable();
resetSource$ = this.resetSource.asObservable();

onSort(sortMeta: SortMeta|SortMeta[]) {
this.sortSource.next(sortMeta);
Expand All @@ -47,6 +49,10 @@ export class TableService {
this.selectionSource.next();
}

onResetChange() {
this.resetSource.next();
}

onContextMenu(data: any) {
this.contextMenuSource.next(data);
}
Expand Down Expand Up @@ -1442,7 +1448,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
this.tableService.onSort(null);

this.filteredValue = null;
this.filters = {};
this.tableService.onResetChange();

this.first = 0;
this.firstChange.emit(this.first);
Expand Down Expand Up @@ -4167,6 +4173,8 @@ export class ColumnFilter implements AfterContentInit {

translationSubscription: Subscription;

resetSubscription: Subscription;

ngOnInit() {
if (!this.dt.filters[this.field]) {
this.initFieldFilterConstraint();
Expand All @@ -4177,6 +4185,10 @@ export class ColumnFilter implements AfterContentInit {
this.generateOperatorOptions();
});

this.resetSubscription = this.dt.tableService.resetSource$.subscribe(() => {
this.clearFilter();
})

this.generateMatchModeOptions();
this.generateOperatorOptions();
}
Expand Down Expand Up @@ -4525,6 +4537,10 @@ export class ColumnFilter implements AfterContentInit {
if (this.translationSubscription) {
this.translationSubscription.unsubscribe();
}

if (this.resetSubscription) {
this.resetSubscription.unsubscribe();
}
}
}

Expand Down

0 comments on commit 979f95e

Please sign in to comment.