Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antd table how to put text into cell in several lines

In Antd is there a way to show the text in table cell into several lines. I try to put </br>, \n, \r into the text.

Is there someone who has already find a way to do that?

like image 627
Vicking Avatar asked Jun 15 '17 08:06

Vicking


People also ask

How do I select rows in ANTD table?

Rows can be selectable by making first column as a selectable column. You can use rowSelection.type to set selection type. Default is checkbox . selection happens when clicking checkbox by default.

How do you use the sorter on an ANTD table?

Once you define sorter it's used for all the dataSource . So, once you click on sorted column - all your data gets sorted. Not very obvious, but you can take a look at this example. If you sort by age - the whole table data gets sorted.

How do I make an ANTD table responsive?

You can make use of the responsive property on the column that you want to control for screen sizes. Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.


2 Answers

Finally here is my solution.

The text for each column contains an \n when there is necessary to have a new line.

After into the table definition I put the style whiteSpace: 'pre':

<Table style={{ whiteSpace: 'pre'}} columns={columns} dataSource={data} title={title} .../>

Thats seems to work as expected.

like image 155
Vicking Avatar answered Oct 05 '22 15:10

Vicking


In the hopes that it's never too late to answer a question here :D

Use the renderer of the table cell, like below, where you can use HTML tags (I'm using React so it's formatted as ReactNode with <> </> parent elements):

const columns = [
    {
      title: "Start",
      dataIndex: "start",
      key: "start",
      render: (text) => <>
      <p>{text.split("@")[0]}</p>
      <p>{text.split("@")[1]}</p>
      </>
    },
    {
      title: "Name",
      dataIndex: "name",
      key: "name",
      render: (text) => text
    }]
like image 27
ikoza Avatar answered Oct 05 '22 16:10

ikoza