2015-07-15 12:16:28 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Menu from 'rc-menu';
|
2015-08-17 18:14:39 +08:00
|
|
|
import Dropdown from '../dropdown';
|
2015-07-15 12:16:28 +08:00
|
|
|
|
2015-09-01 16:18:46 +08:00
|
|
|
let FilterMenu = React.createClass({
|
2015-07-15 12:16:28 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-08-10 17:57:28 +08:00
|
|
|
selectedKeys: this.props.selectedKeys
|
2015-07-15 12:16:28 +08:00
|
|
|
};
|
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
componentWillReceiveProps(nextProps){
|
|
|
|
this.setState({
|
2015-08-10 17:57:28 +08:00
|
|
|
selectedKeys: nextProps.selectedKeys
|
2015-07-31 10:40:23 +08:00
|
|
|
});
|
|
|
|
},
|
2015-07-15 12:16:28 +08:00
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
2015-07-31 10:40:23 +08:00
|
|
|
handleFilter: function () {
|
|
|
|
},
|
2015-07-15 12:16:28 +08:00
|
|
|
column: null
|
|
|
|
};
|
|
|
|
},
|
2015-08-10 17:57:28 +08:00
|
|
|
setSelectedKeys: function ({selectedKeys}) {
|
2015-07-15 12:16:28 +08:00
|
|
|
this.setState({
|
2015-08-10 17:57:28 +08:00
|
|
|
selectedKeys: selectedKeys
|
2015-07-15 12:16:28 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
handleClearFilters() {
|
|
|
|
this.setState({
|
2015-08-10 17:57:28 +08:00
|
|
|
selectedKeys: []
|
2015-08-12 12:47:04 +08:00
|
|
|
}, this.handleConfirm);
|
2015-07-15 12:16:28 +08:00
|
|
|
},
|
2015-08-17 18:14:39 +08:00
|
|
|
handleConfirm() {
|
|
|
|
this.setState({
|
|
|
|
visible: false
|
|
|
|
});
|
2015-08-10 17:57:28 +08:00
|
|
|
this.props.confirmFilter(this.props.column, this.state.selectedKeys);
|
2015-07-31 10:40:23 +08:00
|
|
|
},
|
2015-08-17 18:14:39 +08:00
|
|
|
onVisibleChange(visible) {
|
|
|
|
this.setState({
|
|
|
|
visible: visible
|
|
|
|
});
|
|
|
|
},
|
2015-07-15 12:16:28 +08:00
|
|
|
renderMenus(items) {
|
|
|
|
let menuItems = items.map((item) => {
|
|
|
|
return <Menu.Item key={item.value}>{item.text}</Menu.Item>;
|
|
|
|
});
|
|
|
|
return menuItems;
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
let column = this.props.column;
|
2015-08-17 18:14:39 +08:00
|
|
|
let menus = <Menu multiple={true}
|
2015-07-31 10:40:23 +08:00
|
|
|
prefixCls="ant-dropdown-menu"
|
|
|
|
className="ant-table-filter-dropdown"
|
2015-08-10 17:57:28 +08:00
|
|
|
onSelect={this.setSelectedKeys}
|
|
|
|
onDeselect={this.setSelectedKeys}
|
|
|
|
selectedKeys={this.state.selectedKeys}>
|
2015-07-15 12:16:28 +08:00
|
|
|
{this.renderMenus(column.filters)}
|
|
|
|
<Menu.Divider />
|
|
|
|
<Menu.Item disabled>
|
|
|
|
<a className="ant-table-filter-dropdown-link confirm"
|
2015-07-31 10:40:23 +08:00
|
|
|
style={{
|
2015-08-15 15:08:55 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
pointerEvents: 'visible'
|
|
|
|
}}
|
2015-07-31 10:40:23 +08:00
|
|
|
onClick={this.handleConfirm}>
|
2015-07-15 12:16:28 +08:00
|
|
|
确定
|
|
|
|
</a>
|
|
|
|
<a className="ant-table-filter-dropdown-link clear"
|
2015-07-31 10:40:23 +08:00
|
|
|
style={{
|
2015-08-15 15:08:55 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
pointerEvents: 'visible'
|
|
|
|
}}
|
2015-07-31 10:40:23 +08:00
|
|
|
onClick={this.handleClearFilters}>
|
2015-07-15 12:16:28 +08:00
|
|
|
清空
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>;
|
2015-08-17 18:14:39 +08:00
|
|
|
|
|
|
|
let dropdownSelectedClass = '';
|
|
|
|
if (this.props.selectedKeys.length > 0) {
|
|
|
|
dropdownSelectedClass = 'ant-table-filter-selected';
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Dropdown trigger="click" overlay={menus} visible={this.state.visible} onVisibleChange={this.onVisibleChange}>
|
|
|
|
<i title="筛选" className={'anticon anticon-bars ' + dropdownSelectedClass}></i>
|
|
|
|
</Dropdown>;
|
2015-07-15 12:16:28 +08:00
|
|
|
}
|
|
|
|
});
|
2015-07-31 10:40:23 +08:00
|
|
|
|
|
|
|
export default FilterMenu;
|