2016-11-03 16:05:59 +08:00
|
|
|
---
|
|
|
|
order: 4
|
|
|
|
title:
|
2020-05-13 19:15:40 +08:00
|
|
|
zh-CN: 分页
|
|
|
|
en-US: Pagination
|
2016-11-03 16:05:59 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2020-05-13 19:15:40 +08:00
|
|
|
大数据下使用分页。
|
2016-11-03 16:05:59 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2020-05-13 19:15:40 +08:00
|
|
|
large count of items with pagination.
|
2016-11-03 16:05:59 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Switch, Transfer } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { TransferDirection } from 'antd/es/transfer';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2016-11-03 16:05:59 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
interface RecordType {
|
|
|
|
key: string;
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
chosen: boolean;
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [oneWay, setOneWay] = useState(false);
|
|
|
|
const [mockData, setMockData] = useState<RecordType[]>([]);
|
|
|
|
const [targetKeys, setTargetKeys] = useState<string[]>([]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-05-13 19:15:40 +08:00
|
|
|
const newTargetKeys = [];
|
|
|
|
const newMockData = [];
|
2016-11-03 16:05:59 +08:00
|
|
|
for (let i = 0; i < 2000; i++) {
|
|
|
|
const data = {
|
|
|
|
key: i.toString(),
|
|
|
|
title: `content${i + 1}`,
|
|
|
|
description: `description of content${i + 1}`,
|
2022-09-09 15:51:35 +08:00
|
|
|
chosen: i % 2 === 0,
|
2016-11-03 16:05:59 +08:00
|
|
|
};
|
|
|
|
if (data.chosen) {
|
2020-05-13 19:15:40 +08:00
|
|
|
newTargetKeys.push(data.key);
|
2016-11-03 16:05:59 +08:00
|
|
|
}
|
2020-05-13 19:15:40 +08:00
|
|
|
newMockData.push(data);
|
2016-11-03 16:05:59 +08:00
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2020-05-13 19:15:40 +08:00
|
|
|
setTargetKeys(newTargetKeys);
|
|
|
|
setMockData(newMockData);
|
|
|
|
}, []);
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (newTargetKeys: string[], direction: TransferDirection, moveKeys: string[]) => {
|
2020-05-13 19:15:40 +08:00
|
|
|
console.log(newTargetKeys, direction, moveKeys);
|
|
|
|
setTargetKeys(newTargetKeys);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2020-05-13 19:15:40 +08:00
|
|
|
return (
|
|
|
|
<>
|
2016-11-03 16:05:59 +08:00
|
|
|
<Transfer
|
2020-05-13 19:15:40 +08:00
|
|
|
dataSource={mockData}
|
|
|
|
targetKeys={targetKeys}
|
|
|
|
onChange={onChange}
|
2016-11-03 16:05:59 +08:00
|
|
|
render={item => item.title}
|
2020-05-13 19:15:40 +08:00
|
|
|
oneWay={oneWay}
|
|
|
|
pagination
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<Switch
|
|
|
|
unCheckedChildren="one way"
|
|
|
|
checkedChildren="one way"
|
|
|
|
checked={oneWay}
|
|
|
|
onChange={setOneWay}
|
2016-11-03 16:05:59 +08:00
|
|
|
/>
|
2020-05-13 19:15:40 +08:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2016-11-03 16:05:59 +08:00
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|