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

314
Vistas
How to limit the display size of a table populated from a database?

Im using React, Node, Express, Postgres to populate a table with data taken from postgres. The problem is the table is very long, so ideally I want to only display 5 rows and add a scroll bar to the table.

My table in React:

return <Fragment>

        <div id="ListContactTable">
        <table className="table mt-5" id="ListContactTable">
            <thead>
                <tr>
                    <th>Supplier Name</th>
                    <th>Contact Name</th>
                    <th>Job Title</th>
                    <th>Edit Entry</th>
                    <th>Delete Entry</th>
                </tr>
            </thead>
            <tbody>
                {contacts.map(contact => (
                    <tr key={contact.scontact_id}>
                        <td>{contact.supplier_name}</td>
                        <td>{contact.scontact_name}</td>
                        <td>{contact.scontact_title}</td>
                        <td><EditContact contact={contact} getContact={getContact}/></td>
                        <td><button className="btn btn-danger" onClick={()=> deleteContact(contact.scontact_id)}>Delete</button></td>
                    </tr>
                ))}           
            </tbody>
        </table>
        </div>
        </Fragment>

I have tried using css on both the table and the div it's placed in to try and limit the table height, but it didn't work out:

.modal-body{
  overflow-y:scroll; 
  max-height: 300px;
}
#ListContactTable{
  height: 300px;
}
.modal-dialog {
  width: 600px;
}
.modal-footer {
  border-top: 0 none;
}

So how would I go about limiting the display size of the table, and adding a scrollbar to it?

Solution Just had to add this to my table:

table 
{
    table-layout:fixed;
    width:100%;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

the simplest way is to change your mapping code to:

{contacts.slice(0,5).map(contact => (
                    <tr key={contact.scontact_id}>
                        <td>{contact.supplier_name}</td>
                        <td>{contact.scontact_name}</td>
                        <td>{contact.scontact_title}</td>
                        <td><EditContact contact={contact} getContact={getContact}/></td>
                        <td><button className="btn btn-danger" onClick={()=> deleteContact(contact.scontact_id)}>Delete</button></td>
                    </tr>
                ))}          

another way is goto your node backend and set limit for your GET controller.

about 4 years ago · Juan Pablo Isaza 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