2020-02-29 23:11:02 +08:00
|
|
|
---
|
|
|
|
order: 99
|
|
|
|
title:
|
|
|
|
en-US: Custom selection group
|
|
|
|
zh-CN: 自定义选择项组
|
|
|
|
debug: true
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
自定义选项分组。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Customize selection group.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
|
|
|
import React from 'react';
|
2020-02-29 23:11:02 +08:00
|
|
|
import { Table } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { TableRowSelection } from 'antd/lib/table/interface';
|
|
|
|
import type { ColumnsType } from 'antd/lib/table';
|
2020-02-29 23:11:02 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
interface DataType {
|
|
|
|
key: React.Key;
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const columns: ColumnsType<DataType> = [
|
2020-02-29 23:11:02 +08:00
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const data: DataType[] = [];
|
2020-02-29 23:11:02 +08:00
|
|
|
for (let i = 0; i < 46; i++) {
|
|
|
|
data.push({
|
|
|
|
key: i,
|
|
|
|
name: i % 2 === 0 ? `Edward King ${i}` : 'Another Row',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const rowSelection: TableRowSelection<DataType> = {
|
|
|
|
renderCell: (checked, _record, index, node) => ({
|
2020-02-29 23:11:02 +08:00
|
|
|
props: { rowSpan: index % 2 === 0 ? 2 : 0 },
|
|
|
|
children: (
|
|
|
|
<>
|
|
|
|
{String(checked)}: {node}
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
return <Table rowSelection={rowSelection} columns={columns} dataSource={data} />;
|
|
|
|
};
|
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default App;
|
2020-02-29 23:11:02 +08:00
|
|
|
```
|