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

158
Visualizações
Showing number of elements during paginations

I'm trying to create a way to show the number of elements for each page, for example:

Page1: 1-5 elements of 327

Page2: 6-10 elements of 327

....

Now I have the opportunity to go to the nextPage, previousPage, lastPage, firstPage, and also the possibility to choose the number of element for every page(for example 5, 10, 20) (this.elementsForPage)

I have tried to create in this way:

if(action === "next"){
          this.firstElement += parameters.length
          this.lastElement  += parameters.length
        }
        if(action === "previous"){
          this.firstElement -= parameters.length
          this.lastElement  -= parameters.length
        }
        if(action === "last"){
          this.firstElement = this.totalElements - this.parameters.length
          this.lastElement = this.totalElements
        }
        if(action === "first"){
          this.firstElement = 1;
          this.lastElement = parameters.length 
        }

this works if I make next, previous and first. But it doesn't work If I go on the last page.

This is why If I go to the last page and it has only 2 results, for example, i'll have

firstElement = 327 - 2 = 325

lastElement = 327

But if I go on "previous" it counts:

firstElement = 325 - 5 = 320

lastElement = 327 - 5 = 322

and it is wrong because are showing 5 results not 2.

In your opinion how can I fix these problems?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

This Function

function getCurrentPageItems(currentPage,perPage,total)
{
    currentPage = currentPage - 1;
    let elStart = currentPage*perPage +1;
    let elEnd = elStart+perPage - 1;
    elEnd = Math.min(Math.max(elEnd, 1), total);
    console.log(`Page ${(currentPage+1)}: ${elStart}-${elEnd} of ${total}`);
    return [elEnd,elEnd];
}
getCurrentPageItems(1,5,327);
getCurrentPageItems(2,5,327);
getCurrentPageItems(65,5,327);
getCurrentPageItems(66,5,327);
console.log(327/5);

about 4 years ago · Santiago Gelvez Relatório
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