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

166
Visualizações
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 à 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