ant-design/components/transfer/demo/large-data.md

81 lines
1.7 KiB
Markdown
Raw Normal View History

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