Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
What is a good way to handle server side pagination and loading the data to dropdown?

I am working on an Angular application. It fetches data from ASP.NET Core API, where server side pagination is implemented. In Angular application I have implemented state manager - NGXS.

I need to fetch the API data and display it inside dropdown and table. I have some ideas on doing that and I would like to receive some feedback.

This is what a minified version of my project looks like:

That is one of my StateModels, it stores a list of fetched services (entity) inside a wrapper

export class ServicesStateModel {
    services: PaginatedList<Service[]>; 
}

And this is the Action for fetching the services.

 @Action(FetchServices, { cancelUncompleted: true })
  fetchServices({ getState, setState }: StateContext<ServicesStateModel>, { pageNumber, pageSize }: FetchServices): Observable<ApiResponsePaginated<Service[]>> {
    return this.servicesApiService.getServices(pageNumber, pageSize).pipe(
      tap((result: ApiResponsePaginated<Service[]>) => {
        const { data } = result;
        if (data) {
          const state = getState();
          setState({ ...state, services: new PaginatedList<Service[]>(data.items,data.pageIndex, data.totalPages, data.totalCount), });
        }
      })
    )
  }
  1. Every time I change the page inside the table, FetchServices action is dispatched, resulting in a new API call, and its result being saved to the state model and displayed. Is that correct or should I perhaps fetch more than one page at once? Should I save already displayed pages inside a state, so when I switch back to the previous page I avoid another API call, and get it directly from state or is that an overkill?

  2. Every time I open a component where the table is displayed with no pagination implemented, I dispatch some Fetch action. It results in API call on every component enter. Should I avoid that and store the data in state and call API only on page refresh ?

Thank you for your time.

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda