问题
在写 Antd Table 组件的时候,如果表格内容超出列定义的 width 宽度,单元格内容会换行处理,如何让其单元格宽度自适应内容宽度?
解决
- 给标题单元格设置超出省略号显示
- 表格设置
scroll={{ x: 'max-content'}}
- 内容较长希望全部展示的字段 column 不设置 width
.tableArea :global(.ant-table-thead) > tr > th {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
{
title: '长度固定地址1',
key: 'address',
dataIndex: 'address',
width: 200,
align: 'center',
},
{
title: '长度不固定名字长的地址2',
key: 'address2',
dataIndex: 'address',
align: 'center',
},
效果
查询前:
查询后: