Public
Authored by Melroy van den Berg

Current 'solution' with Angular Paginator service

I tried to use the paginator service now with some 'hacks' for setting the this.paginator.pageIndex= within the component..

File list.component.ts:

    this.paginatorService.pageChange.subscribe((pageEventData) => {
      if (pageEventData.fetchData) {
        if (pageEventData.goToFistPage) {
          // Should return to the first page
          this.paginator.pageIndex = 0;
        }
        this.ledgerService.getAll(pageEventData.url, pageEventData.params)
        .pipe(
          map(resp => {
            this.paginatorService.setError(false);
            this.paginatorService.setPaginationData(resp.headers);
            this.paginatorService.setLoading(false);
            return resp.body;
          }),
          catchError((error) => {
            this.paginatorService.setLoading(false);
            this.paginatorService.setError(true);
            console.error(error);
            return observableOf([]);
          })
        ).subscribe(data => this.dataSource.data = data);
      } else {
        // Only restore old page ID
        this.paginator.pageIndex = pageEventData.pageIndex;
      }
    });
Edited
paginator.service.ts 6.69 KB
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment