Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!