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

207
Visualizações
Make table cell textOverflow dynamic as per width

I have a table with some columns. I want my first 3 columns to have bigger width than others (for example to have width of 15%). So this means that for first 3 columns to use 45% of the width of table. I have this code as in sandbox:

https://codesandbox.io/s/modest-mclean-utqn3e?file=/src/App.js

My idea is when I have wider screen the first 3 columns to show more:

cellStyle: {
    fontStyle: "bold",
    whiteSpace: "nowrap",
    textOverflow: "ellipsis",
    overflow: "hidden",
    textAlign: "center",
    width: "15%"
  }

cellStyle's width property is not working at all.

In current situation all of the columns are equal as width. How can I make them bigger?

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your styles are good, but you forget to set width: 15% for the correlated headers. A table cannot recognize columns' sizes automatically, so you need to set all rows to have the same width.

You can check this sandbox

import React, { useState } from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Box, TextField, Button, Tooltip } from "@material-ui/core";
import plans from "./data";
const useStyles = makeStyles((theme) => ({
  cellStyle: {
    fontStyle: "bold",
    whiteSpace: "nowrap",
    textOverflow: "ellipsis",
    overflow: "hidden",
    textAlign: "center",
    width: "15%"
  },
  headerStyle: {
    width: "15%"
  }
}));
export default function App() {
  const classes = useStyles();

  return (
    <Box>
      <table
        className="table table-striped table-bordered table-sm table-hover"
        style={{ width: "100%", tableLayout: "fixed" }}
      >
        <thead className="thead-dark">
          <tr style={{ textAlign: "center" }}>
            <th className={classes.headerStyle}>Industry</th>
            <th className={classes.headerStyle}>Sponsor</th>
            <th className={classes.headerStyle}>Name</th>
            <th>Compl. Risk</th>
            <th>Plan Util</th>
            <th>ROR</th>
            <th>Expense Ratio</th>
            <th>Retire Rediness</th>
            <th>Cohort</th>
            <th>Overall Grade</th>
            <th>Industry Grade</th>
            <th>Bookmark</th>
          </tr>
        </thead>
        <tbody className="table-hover">
          {plans.map((el, id) => (
            <tr key={el.PlanName + id}>
              <Tooltip title={el.Industry}>
                <td className={classes.cellStyle}>{el.Industry} </td>
              </Tooltip>
              <Tooltip title={el.PlanSponsor}>
                <td className={classes.cellStyle}>{el.PlanSponsor}</td>
              </Tooltip>
              <Tooltip title={el.PlanName}>
                <td className={classes.cellStyle}>{el.PlanName}</td>
              </Tooltip>
              <td>{el.OverallComplRisks}</td>
              <td>{el.OverallPlanUtil}</td>
              <td>{el.OverallROR}</td>
              <td>{el.OverallExpenseRatio}</td>
              <td>{el.OverallRetireReadiness}</td>
              <td>{el.Cohort}</td>
              <td>{el.OverallGrade}</td>
              <td>{el.IndustryGrade}</td>
              <td>{el.IsBookmarked}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </Box>
  );
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe use the feature of HTML5 colSpan ko add the necessary width?

...
...
return (
    <Box>
      <table
        className="table table-striped table-bordered table-sm table-hover"
        style={{ width: "100%", tableLayout: "fixed" }}
      >
        <thead className="thead-dark">
          <tr style={{ textAlign: "center" }}>
            <th colSpan="2">Industry</th>
            <th colSpan="2">Sponsor</th>
            <th colSpan="2">Name</th>
            <th colSpan="1">Compl. Risk</th>
            <th colSpan="1">Plan Util</th>
            <th colSpan="1">ROR</th>
            <th colSpan="1">Expense Ratio</th>
            <th colSpan="1">Retire Rediness</th>
            <th colSpan="1">Cohort</th>
            <th colSpan="1">Overall Grade</th>
            <th colSpan="1">Industry Grade</th>
            <th colSpan="1">Bookmark</th>
          </tr>
        </thead>
        <tbody className="table-hover">
          {plans.map((el, id) => (
            <tr key={el.PlanName + id}>
              <Tooltip title={el.Industry}>
                <td colSpan="2" className={classes.cellStyle}>
                  {el.Industry}{" "}
                </td>
              </Tooltip>
              <Tooltip title={el.PlanSponsor}>
                <td colSpan="2" className={classes.cellStyle}>
                  {el.PlanSponsor}
                </td>
              </Tooltip>
              <Tooltip title={el.PlanName}>
                <td colSpan="2" className={classes.cellStyle}>
                  {el.PlanName}
                </td>
              </Tooltip>
              <td colSpan="1">{el.OverallComplRisks}</td>
              <td colSpan="1">{el.OverallPlanUtil}</td>
              <td colSpan="1">{el.OverallROR}</td>
              <td colSpan="1">{el.OverallExpenseRatio}</td>
              <td colSpan="1">{el.OverallRetireReadiness}</td>
              <td colSpan="1">{el.Cohort}</td>
              <td colSpan="1">{el.OverallGrade}</td>
              <td colSpan="1">{el.IndustryGrade}</td>
              <td colSpan="1">{el.IsBookmarked}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </Box>
  );

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