import React, { useState } from 'react'; import { Table } from 'antd'; import type { TableColumnsType, TableProps } from 'antd'; type TableRowSelection = TableProps['rowSelection']; interface DataType { key: React.Key; name: string; age: number; address: string; } const columns: TableColumnsType = [ { title: 'Name', dataIndex: 'name', }, { title: 'Age', dataIndex: 'age', }, { title: 'Address', dataIndex: 'address', }, ]; const dataSource = Array.from({ length: 46 }).map((_, i) => ({ key: i, name: `Edward King ${i}`, age: 32, address: `London, Park Lane no. ${i}`, })); const App: React.FC = () => { const [selectedRowKeys, setSelectedRowKeys] = useState([]); const onSelectChange = (newSelectedRowKeys: React.Key[]) => { console.log('selectedRowKeys changed: ', newSelectedRowKeys); setSelectedRowKeys(newSelectedRowKeys); }; const rowSelection: TableRowSelection = { selectedRowKeys, onChange: onSelectChange, selections: [ Table.SELECTION_ALL, Table.SELECTION_INVERT, Table.SELECTION_NONE, { key: 'odd', text: 'Select Odd Row', onSelect: (changeableRowKeys) => { let newSelectedRowKeys = []; newSelectedRowKeys = changeableRowKeys.filter((_, index) => { if (index % 2 !== 0) { return false; } return true; }); setSelectedRowKeys(newSelectedRowKeys); }, }, { key: 'even', text: 'Select Even Row', onSelect: (changeableRowKeys) => { let newSelectedRowKeys = []; newSelectedRowKeys = changeableRowKeys.filter((_, index) => { if (index % 2 !== 0) { return true; } return false; }); setSelectedRowKeys(newSelectedRowKeys); }, }, ], }; return rowSelection={rowSelection} columns={columns} dataSource={dataSource} />; }; export default App;