Browse Source

fix: resolve filter problem in ListService

pull/5431/head
mehmet-erim 6 years ago
parent
commit
fbaac23b78
  1. 2
      npm/ng-packs/packages/core/src/lib/services/list.service.ts
  2. 10
      npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

2
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<QueryParamsType = ABP.PageQueryParams> implements OnDestroy { export class ListService<QueryParamsType = ABP.PageQueryParams> implements OnDestroy {
private _filter = ''; private _filter = '';
set filter(value: string) { set filter(value: string) {
if (this._filter !== value) this._page = 0;
this._filter = value; this._filter = value;
this.get(); this.get();
} }

10
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 { export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
private subscription = new Subscription(); private subscription = new Subscription();
private querySubscription: Subscription;
@Input() list: ListService; @Input() list: ListService;
@ -66,12 +67,21 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
this.subscription.add(sub); 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) { ngOnChanges({ list }: SimpleChanges) {
if (!list.firstChange) return; if (!list.firstChange) return;
const { maxResultCount, page } = list.currentValue; const { maxResultCount, page } = list.currentValue;
this.table.limit = maxResultCount; this.table.limit = maxResultCount;
this.table.offset = page; this.table.offset = page;
if (this.querySubscription) this.querySubscription.unsubscribe();
this.subscribeToQuery();
} }
ngOnDestroy() { ngOnDestroy() {

Loading…
Cancel
Save