基础表格带 CheckBox 或者 Radio 选项
CheckBox 选项
import React, { useState } from 'react'
import { Table } from 'antd'
function useBasicTable2() {
const [pagnationPage] = useState('bottomCenter')
const [selectionType] = useState('checkbox')
const columns = [
{
title: '姓名',
width: 100,
dataIndex: 'name',
render: (text) => <div>{text}</div>,
},
{
title: '资产',
width: 100,
className: 'column-money',
dataIndex: 'money',
align: 'center',
},
{
title: '地址',
dataIndex: 'address',
},
]
const data = [
{
key: '1',
name: '张三',
money: '$300,000.00',
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: '李四',
money: '$1,256,000.00',
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: '王五',
money: '$120,000.00',
address: 'Sidney No. 1 Lake Park',
},
]
const HeaderData = () => {
return <div classsname="Footer">这就是头部222</div>
}
const FooterData = () => {
return <div classsname="Footer">这就是尾巴</div>
}
const handleClick = (current, pageSize) => {
console.log(current, pageSize)
console.log(`当前页是${current}`)
console.log(`每页条数${pageSize}`)
}
const rowSelection = {
onChange: (selectedRowKeys, selectedRows) => {
console.log(
`selectedRowKeys: ${selectedRowKeys}`,
'selectedRows: ',
selectedRows
)
},
getCheckboxProps: (record) => ({
disabled: record.name === '张三',
name: record.name,
}),
}
return (
<Table
rowSelection={{
type: selectionType,
...rowSelection,
}}
columns={columns}
dataSource={data}
bordered
title={HeaderData}
footer={FooterData}
pagination={{
position: [pagnationPage],
defaultCurrent: 1,
defaultPageSize: 2,
total: 50,
onChange: handleClick,
}}
/>
)
}
export default useBasicTable2
Radio 选项
import React, { useState } from 'react'
import { Table } from 'antd'
function useBasicTable3() {
const [selectionType] = useState('radio')
const [pagnationPage] = useState('bottomCenter')
const columns = [
{
title: 'Name',
dataIndex: 'name',
render: (text) => <div>{text}</div>,
},
{
title: 'Age',
dataIndex: 'age',
},
{
title: 'Address',
dataIndex: 'address',
},
]
const data = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
},
{
key: '4',
name: 'Disabled User',
age: 99,
address: 'Sidney No. 1 Lake Park',
},
]
const rowSelection = {
onChange: (selectedRowKeys, selectedRows) => {
console.log(
`selectedRowKeys: ${selectedRowKeys}`,
'selectedRows: ',
selectedRows
)
},
getCheckboxProps: (record) => ({
disabled: record.name === 'Disabled User',
name: record.name,
}),
}
const handleClick = (current, pageSize) => {
console.log(current, pageSize)
console.log(`当前页是${current}`)
console.log(`每页条数${pageSize}`)
}
return (
<Table
rowSelection={{
type: selectionType,
...rowSelection,
}}
columns={columns}
dataSource={data}
pagination={{
position: [pagnationPage],
defaultCurrent: 1,
defaultPageSize: 2,
total: 50,
onChange: handleClick,
}}
/>
)
}
export default useBasicTable3