Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda