在Ant Design中,可以使用rowSpan属性来合并表格中的两行。下面是一个示例代码:
import React from "react";
import { Table } from "antd";
const dataSource = [
{
key: "1",
name: "John",
age: 32,
address: "New York"
},
{
key: "2",
name: "Mike",
age: 28,
address: "London"
}
];
const columns = [
{
title: "Name",
dataIndex: "name",
key: "name",
render: (text, record, index) => {
const obj = {
children: text,
props: {}
};
if (index === 0) {
obj.props.rowSpan = 2; // 合并两行
}
return obj;
}
},
{
title: "Age",
dataIndex: "age",
key: "age"
},
{
title: "Address",
dataIndex: "address",
key: "address"
}
];
const App = () => {
return
;
};
export default App;
在上面的代码中,我们在render方法中使用了rowSpan属性来设置第一列的合并行数。当index为0时,也就是第一行时,将rowSpan设置为2,表示要合并两行。