ant-design/components/select/demo/search-sort.md

61 lines
1.0 KiB
Markdown
Raw Normal View History

---
order: 4
title:
zh-CN: 带排序的搜索
en-US: Search with sort
---
## zh-CN
在搜索模式下对过滤结果项进行排序。
## en-US
Search the options with sorting.
```tsx
import { Select } from 'antd';
2022-05-23 14:37:16 +08:00
import React from 'react';
const App: React.FC = () => (
<Select
showSearch
style={{ width: 200 }}
placeholder="Search to Select"
optionFilterProp="children"
filterOption={(input, option) => (option?.label ?? '').includes(input)}
filterSort={(optionA, optionB) =>
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
}
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',
},
]}
/>
);
export default App;
```