Browse Source

Merge branch 'rel-4.0' into dev

pull/6623/head
Halil İbrahim Kalkan 6 years ago
parent
commit
f6ded2101b
  1. 13
      npm/ng-packs/packages/core/src/lib/services/list.service.ts
  2. 16
      npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

13
npm/ng-packs/packages/core/src/lib/services/list.service.ts

@ -17,8 +17,6 @@ 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();
} }
@ -35,6 +33,7 @@ export class ListService<QueryParamsType = ABP.PageQueryParams> implements OnDes
return this._maxResultCount; return this._maxResultCount;
} }
private _skipCount = 0;
private _page = 0; private _page = 0;
set page(value: number) { set page(value: number) {
if (value === this._page) return; if (value === this._page) return;
@ -81,6 +80,7 @@ export class ListService<QueryParamsType = ABP.PageQueryParams> implements OnDes
} }
get = () => { get = () => {
this.resetPageWhenUnchanged();
this._query$.next(({ this._query$.next(({
filter: this._filter || undefined, filter: this._filter || undefined,
maxResultCount: this._maxResultCount, maxResultCount: this._maxResultCount,
@ -110,6 +110,15 @@ export class ListService<QueryParamsType = ABP.PageQueryParams> implements OnDes
ngOnDestroy() { ngOnDestroy() {
this.destroy$.next(); this.destroy$.next();
} }
private resetPageWhenUnchanged() {
const skipCount = this._page * this._maxResultCount;
if (skipCount === this._skipCount) {
this._page = 0;
this._skipCount = 0;
} else this._skipCount = skipCount;
}
} }
export type QueryStreamCreatorCallback<T, QueryParamsType = ABP.PageQueryParams> = ( export type QueryStreamCreatorCallback<T, QueryParamsType = ABP.PageQueryParams> = (

16
npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

@ -68,22 +68,22 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
} }
private subscribeToQuery() { private subscribeToQuery() {
this.querySubscription.add( if (!this.querySubscription.closed) this.querySubscription.unsubscribe();
this.list.query$.subscribe(() => {
if (this.list.page !== this.table.offset) this.table.offset = this.list.page; this.querySubscription = this.list.query$.subscribe(() => {
}), const offset = this.list.page;
); if (this.table.offset !== offset) this.table.offset = offset;
});
} }
ngOnChanges({ list }: SimpleChanges) { ngOnChanges({ list }: SimpleChanges) {
this.subscribeToQuery();
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() {

Loading…
Cancel
Save