|
|
|
@ -18,6 +18,7 @@ import { Subscription } from 'rxjs';
|
|
|
|
|
})
|
|
|
|
|
export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
|
|
|
|
|
private subscription = new Subscription();
|
|
|
|
|
private querySubscription = new Subscription();
|
|
|
|
|
|
|
|
|
|
@Input() list: ListService;
|
|
|
|
|
|
|
|
|
@ -66,16 +67,28 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
|
|
|
|
|
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) {
|
|
|
|
|
if (!list.firstChange) return;
|
|
|
|
|
|
|
|
|
|
const { maxResultCount, page } = list.currentValue;
|
|
|
|
|
this.table.limit = maxResultCount;
|
|
|
|
|
this.table.offset = page;
|
|
|
|
|
|
|
|
|
|
this.querySubscription.unsubscribe();
|
|
|
|
|
this.subscribeToQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
|
this.querySubscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|