How to wrap text in table cell?
I tried a few methods with custom css, none worked. Is there a way to wrap text in a table column?
@jma7889 add the following css inline on the TableRowColumn:
{
whiteSpace: 'normal',
wordWrap: 'break-word'
}
@bezreyhan Thank you!
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>
@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 !
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.
Hi!
@szefoski try using 'wordBreak' instead of 'wordWrap'
{ whiteSpace: 'normal', wordBreak: 'break-word', }
@acjimeneza Hi!
That works, thanks!
Hi!
@szefoski try using 'wordBreak' instead of 'wordWrap'
{ whiteSpace: 'normal', wordBreak: 'break-word', }
Thank You So Much! It worked Perfectly!
Hi!
@szefoski try using 'wordBreak' instead of 'wordWrap'
{ whiteSpace: 'normal', wordBreak: 'break-word', }
thank you so much, life-saviour bro
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 🙇