ant-design/components/form/demo/advanced-search.md

109 lines
2.6 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 3
2016-07-31 09:53:51 +08:00
title:
zh-CN: 高级搜索
en-US: Advanced search
2016-03-31 09:40:55 +08:00
---
2015-12-29 23:39:21 +08:00
2016-07-31 09:53:51 +08:00
## zh-CN
2015-12-29 23:39:21 +08:00
三列栅格式的表单排列方式,常用于数据表格的高级搜索。
有部分定制的样式代码,由于输入标签长度不确定,需要根据具体情况自行调整。
2016-07-31 09:53:51 +08:00
## en-US
Three columns layout is often used for advanced searching of data table.
2016-07-31 09:53:51 +08:00
Because the width of label is not fixed, you may need to adjust it by customizing its style.
2016-07-31 09:53:51 +08:00
2016-08-05 11:47:31 +08:00
2015-12-29 23:39:21 +08:00
````jsx
import { Form, Row, Col, Input, Button, Icon } from 'antd';
2015-12-29 23:39:21 +08:00
const FormItem = Form.Item;
const AdvancedSearchForm = Form.create()(React.createClass({
getInitialState() {
return {
expand: false,
};
},
handleSearch(e) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
console.log('Received values of form: ', values);
});
},
handleReset() {
this.props.form.resetFields();
},
2016-11-02 18:08:48 +08:00
toggle() {
const { expand } = this.state;
this.setState({ expand: !expand });
},
render() {
const { getFieldDecorator } = this.props.form;
const formItemLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 19 },
};
// To generate mock Form.Item
const children = [];
for (let i = 0; i < 10; i++) {
children.push(
<Col span={8} key={i}>
2016-11-02 18:08:48 +08:00
<FormItem {...formItemLayout} label={`Field ${i}`}>
{getFieldDecorator(`field-${i}`)(
<Input placeholder="placeholder" />
)}
</FormItem>
</Col>
);
}
const expand = this.state.expand;
2016-11-02 18:08:48 +08:00
const shownCount = expand ? children.length : 6;
return (
<Form
horizontal
className="ant-advanced-search-form"
onSubmit={this.handleSearch}
>
<Row gutter={40}>
2016-11-02 18:08:48 +08:00
{children.slice(0, shownCount)}
</Row>
<Row>
<Col span={24} style={{ textAlign: 'right' }}>
<Button type="primary" htmlType="submit">Search</Button>
2016-11-02 18:08:48 +08:00
<Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
Clear
</Button>
<a style={{ marginLeft: 8, fontSize: 12 }} onClick={this.toggle}>
Collapse <Icon type={expand ? 'up' : 'down'} />
</a>
</Col>
</Row>
</Form>
);
},
}));
ReactDOM.render(<AdvancedSearchForm />, mountNode);
2015-12-29 23:39:21 +08:00
````
````css
#components-form-demo-advanced-search .ant-advanced-search-form {
padding: 24px;
2016-11-02 18:08:48 +08:00
background: #fbfbfb;
2015-12-29 23:39:21 +08:00
border: 1px solid #d9d9d9;
border-radius: 6px;
}
````
<style>
#components-form-demo-advanced-search .ant-form-horizontal {
2015-12-29 23:39:21 +08:00
max-width: none;
}
</style>