2020-11-06 09:54:30 +08:00
|
|
|
---
|
|
|
|
order: 4
|
|
|
|
title:
|
|
|
|
zh-CN: 带排序的搜索
|
|
|
|
en-US: Search with sort
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
在搜索模式下对过滤结果项进行排序。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Search the options with sorting.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2020-11-06 09:54:30 +08:00
|
|
|
import { Select } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React from 'react';
|
2020-11-06 09:54:30 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2020-11-06 09:54:30 +08:00
|
|
|
<Select
|
|
|
|
showSearch
|
|
|
|
style={{ width: 200 }}
|
|
|
|
placeholder="Search to Select"
|
|
|
|
optionFilterProp="children"
|
2022-09-19 18:01:16 +08:00
|
|
|
filterOption={(input, option) => (option?.label ?? '').includes(input)}
|
2020-11-06 09:54:30 +08:00
|
|
|
filterSort={(optionA, optionB) =>
|
2022-09-19 18:01:16 +08:00
|
|
|
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
|
2020-11-06 09:54:30 +08:00
|
|
|
}
|
2022-09-19 18:01:16 +08:00
|
|
|
options={[
|
|
|
|
{
|
|
|
|
value: '1',
|
|
|
|
label: 'Not Identified',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '2',
|
|
|
|
label: 'Closed',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '3',
|
|
|
|
label: 'Communicated',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '4',
|
|
|
|
label: 'Identified',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '5',
|
|
|
|
label: 'Resolved',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '6',
|
|
|
|
label: 'Cancelled',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2020-11-06 09:54:30 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2020-11-06 09:54:30 +08:00
|
|
|
```
|