19

I am using https://react-table.js.org/#/story/readme for displaying table from server response. But for column data with long length, its showing ellipsis. I am not finding a way for wrapping it, so that full data is displayed.

In the doc, they have mentioned style prop, but I am not able to figure it out. I tried below, but it did not work.

<ReactTable
    data={respDataArr}
    columns={columns}
    style={{overflow:'wrap'}}
/>

Can someone suggest please what change should I do?

xploreraj
  • 3,792
  • 12
  • 33
  • 51
  • is answered here.. https://github.com/react-tools/react-table/issues/578 – Panther Feb 18 '18 at 17:11
  • Thanks @Panther, I tried `Cell: props =>
    {props.value}
    ` but it did not work. Its not showing ellipsis, but cell width has not increased and the data rather goes hiding from the right edge.
    – xploreraj Feb 18 '18 at 17:25
  • u may try some css for ur div.. like word-break: all and width as 100% – Panther Feb 18 '18 at 17:30

4 Answers4

52

You'll want to use the css property white-space: unset;

find the column you want to have wrap text and add the following as a property of the column

// Example Column definition
{
    Header: 'header', 
    accessor: 'data1',
    style: { 'whiteSpace': 'unset' } //Add this line to the column definition
}

Alternatively you can add a class that targets .ReactTable .rt-td directly in your css/sass/scss

Edited: Added example column definition to make it clearer, updated to new react-table api

Steffan
  • 719
  • 5
  • 8
12

To further make the answer clearer according to Steffan:

This is my column definition :

   const responsesData = [{..}, {..} .... etc ..];
   const columsDefnSamplesQsReactTable = [{
        Header: 'Question Code',
        accessor: 'Id'
    }, {
        Header: 'Question Text',
        accessor: 'QuestionText',
        style: { 'white-space': 'unset' } // allow for words wrap inside only this cell
    }];

    <ReactTable data={responsesData} columns= columsDefnSamplesQsReactTable } 
     defaultPageSize={3} />

enter image description here

SmoothyBoothy
  • 195
  • 1
  • 9
3

In order to get this to work for me I had to use this sytnax:

style: { 'whiteSpace': 'unset' } 
EllaVader
  • 141
  • 1
  • 5
0

const columsDefnSamplesQsReactTable = [
  {
    Header: "Question Code",
    accessor: "Id",
  },
  {
    Header: "Question Text",
    accessor: "QuestionText",
    style: { overflowWrap: "break-word" }, // allow for words wrap inside this cell
  },
];