2020-03-27 15:48:42 +08:00
|
|
|
---
|
|
|
|
order: 99
|
|
|
|
title:
|
|
|
|
en-US: Pagination Settings
|
|
|
|
zh-CN: 分页设置
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
表格的分页设置。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Table pagination settings.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Radio, Space, Table, Tag } from 'antd';
|
2022-07-04 22:09:54 +08:00
|
|
|
import type { ColumnsType } from 'antd/es/table';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useState } from 'react';
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
interface DataType {
|
|
|
|
key: string;
|
|
|
|
name: string;
|
|
|
|
age: number;
|
|
|
|
address: string;
|
|
|
|
tags: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
type TablePaginationPosition =
|
|
|
|
| 'topLeft'
|
|
|
|
| 'topCenter'
|
|
|
|
| 'topRight'
|
|
|
|
| 'bottomLeft'
|
|
|
|
| 'bottomCenter'
|
|
|
|
| 'bottomRight';
|
2020-03-27 15:48:42 +08:00
|
|
|
|
|
|
|
const topOptions = [
|
|
|
|
{ label: 'topLeft', value: 'topLeft' },
|
|
|
|
{ label: 'topCenter', value: 'topCenter' },
|
|
|
|
{ label: 'topRight', value: 'topRight' },
|
|
|
|
{ label: 'none', value: 'none' },
|
|
|
|
];
|
|
|
|
|
|
|
|
const bottomOptions = [
|
|
|
|
{ label: 'bottomLeft', value: 'bottomLeft' },
|
|
|
|
{ label: 'bottomCenter', value: 'bottomCenter' },
|
|
|
|
{ label: 'bottomRight', value: 'bottomRight' },
|
|
|
|
{ label: 'none', value: 'none' },
|
|
|
|
];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const columns: ColumnsType<DataType> = [
|
2020-03-27 15:48:42 +08:00
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
2020-08-04 17:49:31 +08:00
|
|
|
render: text => <a>{text}</a>,
|
2020-03-27 15:48:42 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
dataIndex: 'address',
|
|
|
|
key: 'address',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Tags',
|
|
|
|
key: 'tags',
|
|
|
|
dataIndex: 'tags',
|
2022-05-19 09:46:26 +08:00
|
|
|
render: (tags: string[]) => (
|
2020-03-27 15:48:42 +08:00
|
|
|
<span>
|
2020-08-04 17:49:31 +08:00
|
|
|
{tags.map(tag => {
|
2020-03-27 15:48:42 +08:00
|
|
|
let color = tag.length > 5 ? 'geekblue' : 'green';
|
|
|
|
if (tag === 'loser') {
|
|
|
|
color = 'volcano';
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Tag color={color} key={tag}>
|
|
|
|
{tag.toUpperCase()}
|
|
|
|
</Tag>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Action',
|
|
|
|
key: 'action',
|
2022-05-19 09:46:26 +08:00
|
|
|
render: (_, record) => (
|
2020-08-04 17:49:31 +08:00
|
|
|
<Space size="middle">
|
|
|
|
<a>Invite {record.name}</a>
|
2020-03-27 15:48:42 +08:00
|
|
|
<a>Delete</a>
|
2020-08-04 17:49:31 +08:00
|
|
|
</Space>
|
2020-03-27 15:48:42 +08:00
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const data: DataType[] = [
|
2020-03-27 15:48:42 +08:00
|
|
|
{
|
|
|
|
key: '1',
|
|
|
|
name: 'John Brown',
|
|
|
|
age: 32,
|
|
|
|
address: 'New York No. 1 Lake Park',
|
|
|
|
tags: ['nice', 'developer'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '2',
|
|
|
|
name: 'Jim Green',
|
|
|
|
age: 42,
|
|
|
|
address: 'London No. 1 Lake Park',
|
|
|
|
tags: ['loser'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '3',
|
|
|
|
name: 'Joe Black',
|
|
|
|
age: 32,
|
|
|
|
address: 'Sidney No. 1 Lake Park',
|
|
|
|
tags: ['cool', 'teacher'],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [top, setTop] = useState<TablePaginationPosition>('topLeft');
|
|
|
|
const [bottom, setBottom] = useState<TablePaginationPosition>('bottomRight');
|
2020-03-27 15:48:42 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2020-03-27 15:48:42 +08:00
|
|
|
<div>
|
|
|
|
<Radio.Group
|
|
|
|
style={{ marginBottom: 10 }}
|
2022-05-19 09:46:26 +08:00
|
|
|
options={topOptions}
|
|
|
|
value={top}
|
2020-08-04 17:49:31 +08:00
|
|
|
onChange={e => {
|
2022-05-19 09:46:26 +08:00
|
|
|
setTop(e.target.value);
|
2020-03-27 15:48:42 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-05-19 09:46:26 +08:00
|
|
|
<Radio.Group
|
|
|
|
style={{ marginBottom: 10 }}
|
|
|
|
options={bottomOptions}
|
|
|
|
value={bottom}
|
|
|
|
onChange={e => {
|
|
|
|
setBottom(e.target.value);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Table columns={columns} pagination={{ position: [top, bottom] }} dataSource={data} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2020-03-27 15:48:42 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2020-03-27 15:48:42 +08:00
|
|
|
```
|