动态的ANTD表标题 - RECT
我在这里使用ANTD表,我成功地垂直填充了一个标题
,我想水平填充另一个,请参阅图像以进行澄清。
这是我的表列:
const columns = [
{
title: 'Days',
dataIndex: 'date',
defaultSorter: 'ascend',
key: 'title',
sorter: (a, b) => a.date.localeCompare(b.date),
sortDirections: ['descend', 'ascend'],
render: (date) => getDayName(new Date(date)),
},
{
title: 'period',
dataIndex: 'period',
},
}
数据源或来自API的数据:
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [query, setQuery] = useState('');
const fetchData = async () => {
setLoading(true);
const { data } = await getTimetable();
setData(data);
setLoading(false);
};
useEffect(() => {
fetchData();
}, []);
渲染表数据:
<TableContainer columns={columns} rowKey={(record) => record.login.uuid} dataSource={data} />
我想实现的目标:
我现在拥有的:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
ANTD
表中,列需要按以下格式传递。因此,要从您获得的响应数据中创建动态列,首先需要创建对象(COLS)作为上述格式,该格式需要通过
&lt; table; table; table; table colums = {forsatedcolsfromresponsedata}
。因此,在您的情况下,您需要创建列[]如下格式。
使用以下方法,您可以通过传递响应数据来根据需要的格式创建COLS。
假设响应数据仅具有唯一的“周期” ,则此方法工作。
现在,您可以将此方法传递到
列
表格
中的prop 带有返回动态cols的响应数据。检查此完整演示代码。
In
antd
Table, columns need to passed as below format.So to create dynamic columns from the response data you get here, 1st you need to create the array of objects (cols) as the above format that need to pass for
<Table columns={formattedColsfromResponseData}
.So in your case you need to create columns[] like below format.
With the below method you can create cols as required format by passing the response data.
This method works assuming response data has only unique 'Periods'.
Now you can pass this method to
columns
prop inTable
with response data which returns the dynamic cols.Check this full demo antd-dynamic-cols-example code.