2019-07-03 20:14:39 +08:00
|
|
|
|
---
|
|
|
|
|
order: 13
|
|
|
|
|
title:
|
|
|
|
|
zh-CN: 高级搜索
|
|
|
|
|
en-US: Advanced search
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
|
|
三列栅格式的表单排列方式,常用于数据表格的高级搜索。
|
|
|
|
|
|
|
|
|
|
有部分定制的样式代码,由于输入标签长度不确定,需要根据具体情况自行调整。
|
|
|
|
|
|
2021-04-14 19:00:01 +08:00
|
|
|
|
> 🛎️ 想要 3 分钟实现? 试试 ProForm 的[查询表单](https://procomponents.ant.design/components/form#%E6%9F%A5%E8%AF%A2%E7%AD%9B%E9%80%89)!
|
2020-11-27 18:29:21 +08:00
|
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
|
|
Three columns layout is often used for advanced searching of data table.
|
|
|
|
|
|
|
|
|
|
Because the width of label is not fixed, you may need to adjust it by customizing its style.
|
|
|
|
|
|
|
|
|
|
```tsx
|
2019-11-28 12:34:33 +08:00
|
|
|
|
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
2022-05-21 22:14:15 +08:00
|
|
|
|
import { Button, Col, Form, Input, Row, Select } from 'antd';
|
|
|
|
|
import React, { useState } from 'react';
|
2019-07-03 20:14:39 +08:00
|
|
|
|
|
2022-02-18 15:46:59 +08:00
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
|
const AdvancedSearchForm = () => {
|
2020-01-22 12:11:49 +08:00
|
|
|
|
const [expand, setExpand] = useState(false);
|
2019-07-03 20:14:39 +08:00
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
const getFields = () => {
|
|
|
|
|
const count = expand ? 10 : 6;
|
|
|
|
|
const children = [];
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
|
children.push(
|
|
|
|
|
<Col span={8} key={i}>
|
|
|
|
|
<Form.Item
|
|
|
|
|
name={`field-${i}`}
|
|
|
|
|
label={`Field ${i}`}
|
|
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Input something!',
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>
|
2022-02-18 15:46:59 +08:00
|
|
|
|
{i % 3 !== 1 ? (
|
|
|
|
|
<Input placeholder="placeholder" />
|
|
|
|
|
) : (
|
|
|
|
|
<Select defaultValue="2">
|
|
|
|
|
<Option value="1">1</Option>
|
|
|
|
|
<Option value="2">
|
|
|
|
|
longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong
|
|
|
|
|
</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
)}
|
2019-07-03 20:14:39 +08:00
|
|
|
|
</Form.Item>
|
|
|
|
|
</Col>,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return children;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
|
const onFinish = (values: any) => {
|
2019-07-03 20:14:39 +08:00
|
|
|
|
console.log('Received values of form: ', values);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form
|
|
|
|
|
form={form}
|
|
|
|
|
name="advanced_search"
|
|
|
|
|
className="ant-advanced-search-form"
|
|
|
|
|
onFinish={onFinish}
|
|
|
|
|
>
|
|
|
|
|
<Row gutter={24}>{getFields()}</Row>
|
|
|
|
|
<Row>
|
|
|
|
|
<Col span={24} style={{ textAlign: 'right' }}>
|
|
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
|
|
Search
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
2020-03-30 21:23:05 +08:00
|
|
|
|
style={{ margin: '0 8px' }}
|
2019-07-03 20:14:39 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
form.resetFields();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Clear
|
|
|
|
|
</Button>
|
|
|
|
|
<a
|
2020-03-30 21:23:05 +08:00
|
|
|
|
style={{ fontSize: 12 }}
|
2019-07-03 20:14:39 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
setExpand(!expand);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2019-11-29 14:27:47 +08:00
|
|
|
|
{expand ? <UpOutlined /> : <DownOutlined />} Collapse
|
2019-07-03 20:14:39 +08:00
|
|
|
|
</a>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
|
const App: React.FC = () => (
|
2019-07-03 20:14:39 +08:00
|
|
|
|
<div>
|
|
|
|
|
<AdvancedSearchForm />
|
|
|
|
|
<div className="search-result-list">Search Result List</div>
|
2022-04-03 23:27:45 +08:00
|
|
|
|
</div>
|
2019-07-03 20:14:39 +08:00
|
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
|
|
export default App;
|
2019-07-03 20:14:39 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```css
|
2020-03-29 10:39:46 +08:00
|
|
|
|
[data-theme='compact'] .ant-advanced-search-form,
|
2019-07-03 20:14:39 +08:00
|
|
|
|
.ant-advanced-search-form {
|
2022-03-30 14:13:36 +08:00
|
|
|
|
padding: 24px !important;
|
2019-07-03 20:14:39 +08:00
|
|
|
|
background: #fbfbfb;
|
|
|
|
|
border: 1px solid #d9d9d9;
|
2019-12-24 20:58:42 +08:00
|
|
|
|
border-radius: 2px;
|
2019-07-03 20:14:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 10:39:46 +08:00
|
|
|
|
[data-theme='compact'] .ant-advanced-search-form .ant-form-item,
|
2019-07-03 20:14:39 +08:00
|
|
|
|
.ant-advanced-search-form .ant-form-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 10:39:46 +08:00
|
|
|
|
[data-theme='compact'] .ant-advanced-search-form .ant-form-item-control-wrapper,
|
2019-07-03 20:14:39 +08:00
|
|
|
|
.ant-advanced-search-form .ant-form-item-control-wrapper {
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
#components-form-demo-advanced-search .ant-form {
|
|
|
|
|
max-width: none;
|
|
|
|
|
}
|
|
|
|
|
#components-form-demo-advanced-search .search-result-list {
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
border: 1px dashed #e9e9e9;
|
2019-12-23 20:07:56 +08:00
|
|
|
|
border-radius: 2px;
|
2019-07-03 20:14:39 +08:00
|
|
|
|
background-color: #fafafa;
|
|
|
|
|
min-height: 200px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding-top: 80px;
|
|
|
|
|
}
|
2019-12-23 20:07:56 +08:00
|
|
|
|
[data-theme="dark"] .ant-advanced-search-form {
|
|
|
|
|
background: rgba(255,255,255,0.04);
|
|
|
|
|
border: 1px solid #434343;
|
2019-12-24 20:58:42 +08:00
|
|
|
|
padding: 24px;
|
|
|
|
|
border-radius: 2px;
|
2019-12-23 20:07:56 +08:00
|
|
|
|
}
|
|
|
|
|
[data-theme="dark"] #components-form-demo-advanced-search .search-result-list {
|
|
|
|
|
border: 1px dashed #434343;
|
|
|
|
|
background: rgba(255,255,255,0.04);
|
|
|
|
|
}
|
2019-07-03 20:14:39 +08:00
|
|
|
|
</style>
|