在Antd中,可以通过使用fixed
属性来实现固定宽度的列。以下是一个示例代码:
import React from 'react';
import { Table } from 'antd';
const dataSource = [
{
key: '1',
name: 'John',
age: 26,
address: 'New York',
},
{
key: '2',
name: 'Mike',
age: 32,
address: 'London',
},
// ...
];
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
width: 200, // 设置固定宽度为200px
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
},
// ...
];
const App = () => {
return (
);
};
export default App;
在上述代码中,columns
数组中的Name
列被设置为固定宽度为200px。这样,无论单元格内容的长度如何,该列的宽度都将保持不变。
上一篇:antd中的DatePicker抛出错误:“无法找到dayjsGenerateConfig的导入:从'rc-picker/lib/generate/dayjs'。”
下一篇:Antd中的Markdown