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

Text Overflow: ellipsis

Open vinceliu21 opened this issue 7 years ago • 6 comments

I have created a smaller width table. The cell of one column sometimes will have very long pieces of text. Currently the cell body keeps wrapping/stacking on top of each other and the row grows exponentially large in the table. Is there a way to do turn this cell into an ellipsis? I tried using cellStyle with textOverflow: ellipsis, but it did not work.

image

vinceliu21 avatar Feb 24 '19 07:02 vinceliu21

Hi @vinceliu21 ,

I will try your case asap.

mbrn avatar Feb 24 '19 17:02 mbrn

Thanks! Let me know if you want to see the code I tried or more pictures. Preferably, I would like the rows to stay the same size instead of having one row of data be 3x the size of another because the text in a cell was too long.

vinceliu21 avatar Feb 24 '19 18:02 vinceliu21

Hi @vinceliu21 ,

Can you try this cellStyle

cellStyle: { textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden', maxWidth: 100}

mbrn avatar Mar 04 '19 12:03 mbrn

I was going to ask about the possibility of displaying the full text in a tooltip, then I thought that it is better to show this in a detail component

rikr2sanchez avatar Dec 09 '20 23:12 rikr2sanchez

Addtional option:

import styled from 'styled-components';

const TextOverflow = styled.div`
  width: ${(props) => (props.width ? `${props.width}px` : '300px')};
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
`;

export default TextOverflow;

Then, modify the render and could be reused on any other column.

render: (rowData) => (
      <TextOverflow width="100">{rowData.description}</TextOverflow>
    ),

haroldjcastillo avatar Mar 27 '21 21:03 haroldjcastillo

None of these works for me :/ please help

chen-bowen avatar Jun 29 '21 19:06 chen-bowen