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

163
Vistas
Size of the column based on the header

I am trying to create table in using react, and I want whole column to have the same size as the header.

How do I achieve that?

I have:

function Table() {

    const [data, updateData] = React.useState({
        columns: [],
        values: []
    });

    useEffect(() => {
        fetchData();
    }, [""]);

    const fetchData = () => {
        fetch("http://localhost:8090/").then(response => {
            return response.json()
        }).then(data => {
            updateData(data);
        })
    }

    return <div className="GridTable">
        <TableHeader values={data.columns}/>
    </div>

}

export default Table;

For table header I have

class TableHeader extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return <div className="TableHeader">
            {
                this.props.values.map( value => (
                    <div className="headerItem">{value}</div>
                ))
            }
        </div>
    }
}

export default TableHeader;

and for other rows:

class TableRows extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return <div className="TableRows">
            {
                this.props.values.map( value => (
                    <div className="headerItem">{value}</div>
                ))
            }
        </div>
    }
}

export default TableRows;

Now for css, i use flexBox:

.GridTable{
    position: relative;
    display: flex;
    width: auto;
    grid: auto;

}

.TableHeader, .TableRows{
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: row
}

.headerItem{
    flex: none
}

However when the column name is name (e.g first value in column), its cell has 10px width, but if any name is longer/shorted its cell has different size.

How to fix the width of the column? Thanks for help!

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