From 103d74f32f8aad0139e4cf423054ffe69942a00c Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 18 Jun 2020 16:31:38 +0300 Subject: [PATCH 1/3] fix: catch errors in list service query hook --- .../packages/core/src/lib/services/list.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 3aff601f7a..d3da082eeb 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 @@ -1,6 +1,6 @@ import { Inject, Injectable, OnDestroy, Optional } from '@angular/core'; -import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs'; -import { debounceTime, shareReplay, switchMap, tap } from 'rxjs/operators'; +import { BehaviorSubject, Observable, of, ReplaySubject } from 'rxjs'; +import { catchError, debounceTime, filter, shareReplay, switchMap, tap } from 'rxjs/operators'; import { ABP } from '../models/common'; import { PagedResultDto } from '../models/dtos'; import { LIST_QUERY_DEBOUNCE_TIME } from '../tokens/list.token'; @@ -88,7 +88,8 @@ export class ListService implements OnDes this._isLoading$.next(true); return this.query$.pipe( - switchMap(streamCreatorCallback), + switchMap(query => streamCreatorCallback(query).pipe(catchError(() => of(null)))), + filter(Boolean), tap(() => this._isLoading$.next(false)), shareReplay({ bufferSize: 1, refCount: true }), takeUntilDestroy(this), From 0130157998e790ed4eac76b1cdbe349aaf47a5b0 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 18 Jun 2020 16:40:25 +0300 Subject: [PATCH 2/3] feat: add an empty state to datatable sorting --- .../lib/directives/ngx-datatable-list.directive.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 85e574d63d..f7d7034d28 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 @@ -36,8 +36,15 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit { private subscribeToSort() { const sub = this.table.sort.subscribe(({ sorts: [{ prop, dir }] }) => { - this.list.sortKey = prop; - this.list.sortOrder = dir; + if (prop === this.list.sortKey && this.list.sortOrder === 'desc') { + this.list.sortKey = ''; + this.list.sortOrder = ''; + this.table.sorts = []; + this.cdRef.detectChanges(); + } else { + this.list.sortKey = prop; + this.list.sortOrder = dir; + } }); this.subscription.add(sub); } From 6c9b4c64a9ead34f997731eaaaad7f9be9a40be3 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 18 Jun 2020 16:53:31 +0300 Subject: [PATCH 3/3] fix: avoid ExpressionChangedAfterItHasBeenCheckedError --- .../src/lib/directives/ngx-datatable-list.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7d7034d28..a16925ebd7 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 @@ -52,7 +52,7 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit { private subscribeToIsLoading() { const sub = this.list.isLoading$.subscribe(loading => { this.table.loadingIndicator = loading; - this.cdRef.markForCheck(); + this.cdRef.detectChanges(); }); this.subscription.add(sub); }