You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.4 KiB
92 lines
2.4 KiB
10 years ago
|
import React from 'react';
|
||
|
import Menu from 'rc-menu';
|
||
9 years ago
|
import Dropdown from '../dropdown';
|
||
10 years ago
|
|
||
9 years ago
|
var FilterMenu = React.createClass({
|
||
10 years ago
|
getInitialState() {
|
||
|
return {
|
||
9 years ago
|
selectedKeys: this.props.selectedKeys
|
||
10 years ago
|
};
|
||
|
},
|
||
9 years ago
|
componentWillReceiveProps(nextProps){
|
||
|
this.setState({
|
||
9 years ago
|
selectedKeys: nextProps.selectedKeys
|
||
9 years ago
|
});
|
||
|
},
|
||
10 years ago
|
getDefaultProps() {
|
||
|
return {
|
||
9 years ago
|
handleFilter: function () {
|
||
|
},
|
||
10 years ago
|
column: null
|
||
|
};
|
||
|
},
|
||
9 years ago
|
setSelectedKeys: function ({selectedKeys}) {
|
||
10 years ago
|
this.setState({
|
||
9 years ago
|
selectedKeys: selectedKeys
|
||
10 years ago
|
});
|
||
|
},
|
||
|
handleClearFilters() {
|
||
|
this.setState({
|
||
9 years ago
|
selectedKeys: []
|
||
9 years ago
|
}, this.handleConfirm);
|
||
10 years ago
|
},
|
||
9 years ago
|
handleConfirm() {
|
||
|
this.setState({
|
||
|
visible: false
|
||
|
});
|
||
9 years ago
|
this.props.confirmFilter(this.props.column, this.state.selectedKeys);
|
||
9 years ago
|
},
|
||
9 years ago
|
onVisibleChange(visible) {
|
||
|
this.setState({
|
||
|
visible: visible
|
||
|
});
|
||
|
},
|
||
10 years ago
|
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;
|
||
9 years ago
|
let menus = <Menu multiple={true}
|
||
9 years ago
|
prefixCls="ant-dropdown-menu"
|
||
|
className="ant-table-filter-dropdown"
|
||
9 years ago
|
onSelect={this.setSelectedKeys}
|
||
|
onDeselect={this.setSelectedKeys}
|
||
|
selectedKeys={this.state.selectedKeys}>
|
||
10 years ago
|
{this.renderMenus(column.filters)}
|
||
|
<Menu.Divider />
|
||
|
<Menu.Item disabled>
|
||
|
<a className="ant-table-filter-dropdown-link confirm"
|
||
9 years ago
|
style={{
|
||
9 years ago
|
cursor: 'pointer',
|
||
|
pointerEvents: 'visible'
|
||
|
}}
|
||
9 years ago
|
onClick={this.handleConfirm}>
|
||
10 years ago
|
确定
|
||
|
</a>
|
||
|
<a className="ant-table-filter-dropdown-link clear"
|
||
9 years ago
|
style={{
|
||
9 years ago
|
cursor: 'pointer',
|
||
|
pointerEvents: 'visible'
|
||
|
}}
|
||
9 years ago
|
onClick={this.handleClearFilters}>
|
||
10 years ago
|
清空
|
||
|
</a>
|
||
|
</Menu.Item>
|
||
|
</Menu>;
|
||
9 years ago
|
|
||
|
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>;
|
||
10 years ago
|
}
|
||
|
});
|
||
9 years ago
|
|
||
|
export default FilterMenu;
|