Browse Source

Merge pull request #5431 from abpframework/fix/5429

Resolve filter problem in ListService
pull/5434/head
Mehmet Erim 6 years ago
committed by GitHub
parent
commit
cc099228c9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/core/src/lib/services/list.service.ts
  2. 13
      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();
} }

13
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 = new Subscription();
@Input() list: ListService; @Input() list: ListService;
@ -66,16 +67,28 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
this.subscription.add(sub); this.subscription.add(sub);
} }
private subscribeToQuery() {
this.querySubscription.add(
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;
this.querySubscription.unsubscribe();
this.subscribeToQuery();
} }
ngOnDestroy() { ngOnDestroy() {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
this.querySubscription.unsubscribe();
} }
ngOnInit() { ngOnInit() {

Loading…
Cancel
Save