How to bind pager with http request from service

1 Answer 120 Views
Pager
Pedro
Top achievements
Rank 2
Pedro asked on 09 Jun 2023, 05:18 PM | edited on 09 Jun 2023, 05:18 PM

Hi,

I have a service with a http request to an api that returns a Observable<Pendentes[]>.

I need to call the service in my component, but I can't get the pagination working.

I attached some prints of my code.

 

Best regards,
Pedro Marquinhos

1 Answer, 1 is accepted

Sort by
0
Slavena
Telerik team
answered on 14 Jun 2023, 04:07 PM

Hello Pedro,

Thank you for the provided details and screenshots.

I am not entirely sure what the issue at hand is based on the provided information. I will try to address this case to the best of my understanding.

In order to split the data correctly into pages, the Pager needs the skip, pageSize and total properties set. When the page is changed, the Pager updates the skip and take properties and emits them in the pageChange event. The developer can then retrieve and utilize them for the server request that will return the data corresponding to the current page, e.g.:

public onPageChange(state: PageChangeEvent): void {
    this.skip = state.skip;
    this.service.query({ skip: this.skip, take: 2 });
}

Here is a sample StackBlitz demo that demonstrates utilizing the Pager with remote data:

https://stackblitz.com/edit/angular-pffysc?file=src%2Fapp%2Fapp.component.ts

Please note that this is just an example and backend communication and data retrieval are in the hands of the developer and are out of the support scope.

I hope this steers you in the right direction.

Regards,
Slavena
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
Pager
Asked by
Pedro
Top achievements
Rank 2
Answers by
Slavena
Telerik team
Share this question
or