From fbaac23b78b3166da88142d2f55b3e0a15bc8d20 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Wed, 16 Sep 2020 16:16:42 +0300 Subject: [PATCH] fix: resolve filter problem in ListService --- .../packages/core/src/lib/services/list.service.ts | 2 ++ .../src/lib/directives/ngx-datatable-list.directive.ts | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/npm/ng-packs/packages/core/src/lib/services/list.service.ts b/npm/ng-packs/packages/core/src/lib/services/list.service.ts index 3ebb6dc193..1a1e7c1aeb 100644 --- a/npm/ng-packs/packages/core/src/lib/services/list.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/list.service.ts @@ -17,6 +17,8 @@ import { LIST_QUERY_DEBOUNCE_TIME } from '../tokens/list.token'; export class ListService implements OnDestroy { private _filter = ''; set filter(value: string) { + if (this._filter !== value) this._page = 0; + this._filter = value; this.get(); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts b/npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts index b721e1142a..6cd2ef4031 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts @@ -18,6 +18,7 @@ import { Subscription } from 'rxjs'; }) export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit { private subscription = new Subscription(); + private querySubscription: Subscription; @Input() list: ListService; @@ -66,12 +67,21 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit { this.subscription.add(sub); } + private subscribeToQuery() { + this.querySubscription = this.list.query$.subscribe(() => { + if (this.list.page !== this.table.offset) this.table.offset = this.list.page; + }); + } + ngOnChanges({ list }: SimpleChanges) { if (!list.firstChange) return; const { maxResultCount, page } = list.currentValue; this.table.limit = maxResultCount; this.table.offset = page; + + if (this.querySubscription) this.querySubscription.unsubscribe(); + this.subscribeToQuery(); } ngOnDestroy() {