material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

How to wrap text in table cell?

Open jma7889 opened this issue 11 years ago • 10 comments

I tried a few methods with custom css, none worked. Is there a way to wrap text in a table column?

jma7889 avatar Nov 06 '15 16:11 jma7889

@jma7889 add the following css inline on the TableRowColumn:

{
  whiteSpace: 'normal',
  wordWrap: 'break-word'
}

bezreyhan avatar Jan 20 '16 05:01 bezreyhan

@bezreyhan Thank you!

jma7889 avatar Jan 20 '16 13:01 jma7889

Here is an example of @bezreyhan solution.

I had to add it on the cell where i need word-wrap on the TableCell.

<Table>
          <TableHead>
            <TableRow>
              <TableCell>TARIC</TableCell>
              <TableCell>DESCRIPTION</TableCell>
              <TableCell>js-levenshtein</TableCell>
              <TableCell>fuzzball.ratio</TableCell>
            </TableRow>
          </TableHead>
          <TableBody>
            {taricData.map(n => {
              return (
                <TableRow key={n._id}>
                  <TableCell>
                    {n.hsChapter}
                    {n.hsHeading}
                    {n.hsSubheading}
                    {n.cnSubheading}
                    {n.taricCode}
                  </TableCell>
                  <TableCell
                    style={{
                      whiteSpace: "normal",
                      wordWrap: "break-word"
                    }}
                  >
                    <Highlighter
                      highlightClassName="highlightText"
                      searchWords={[
                        this.state.searchQuery.partName.replace(/[*]/g, "")
                      ]}
                      textToHighlight={n.description}
                    />
                    {n.description}
                  </TableCell>
                  <TableCell>
                    {levenshtein(
                      this.state.searchQuery.partName.replace(/[*]/g, ""),
                      n.description
                    )}
                  </TableCell>
                  <TableCell>
                    {fuzzball.ratio(
                      this.state.searchQuery.partName.replace(/[*]/g, ""),
                      n.description
                    )}{" "}
                    %
                  </TableCell>
                </TableRow>
              );
            })}
          </TableBody>
        </Table>

isaklafleur avatar Sep 09 '17 21:09 isaklafleur

@jma7889 add the following css inline on the TableRowColumn:

{
  whiteSpace: 'normal',
  wordWrap: 'break-word'
}

Thank you so much!!!! I have been searching for this fix for a while, and yours is the only one that worked !

lima-william avatar Oct 18 '19 18:10 lima-william

Hi,

It looks like this solution doesn't work anymore. Please check the example below: https://codesandbox.io/s/material-ui-tablle-cell-wordwrap-zsopi

You can see 'wordWrap' works fine for a div and doesn't work for TableCell.

szefoski avatar May 27 '20 22:05 szefoski

Hi!

@szefoski try using 'wordBreak' instead of 'wordWrap'

{ whiteSpace: 'normal', wordBreak: 'break-word', }

acjimeneza avatar Jun 15 '20 04:06 acjimeneza

@acjimeneza Hi!

That works, thanks!

szefoski avatar Jul 06 '20 18:07 szefoski

Hi!

@szefoski try using 'wordBreak' instead of 'wordWrap'

{ whiteSpace: 'normal', wordBreak: 'break-word', }

Thank You So Much! It worked Perfectly!

marsh826 avatar Jun 06 '21 16:06 marsh826

Hi!

@szefoski try using 'wordBreak' instead of 'wordWrap'

{ whiteSpace: 'normal', wordBreak: 'break-word', }

thank you so much, life-saviour bro

MazanLabeeb avatar Feb 14 '23 10:02 MazanLabeeb

Hi!

@szefoski try using 'wordBreak' instead of 'wordWrap'

{ whiteSpace: 'normal', wordBreak: 'break-word', }

Been searching about it for the whole day. It worked for me. Thank you much 🙇‍

dizonb avatar Feb 12 '24 00:02 dizonb