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.

84 lines
2.2 KiB

import React from 'react';
import Menu from 'rc-menu';
9 years ago
var FilterMenu = React.createClass({
getInitialState() {
return {
9 years ago
selectedFilters: this.props.selectedFilters
};
},
9 years ago
componentWillReceiveProps(nextProps){
this.setState({
selectedFilters: nextProps.selectedFilters
});
},
getDefaultProps() {
return {
9 years ago
handleFilter: function () {
},
column: null
};
},
9 years ago
handleSelectFilter: function (selected) {
this.setState({
9 years ago
selectedFilters: this.state.selectedFilters.concat(selected)
});
},
9 years ago
handleDeselectFilter: function (key) {
var index = this.state.selectedFilters.indexOf(key);
if (index !== -1) {
9 years ago
var selectedFilters = this.state.selectedFilters.concat();
selectedFilters.splice(index, 1);
this.setState({
selectedFilters: selectedFilters
});
}
},
handleClearFilters() {
this.setState({
selectedFilters: []
});
},
9 years ago
handleConfirm(){
this.props.confirmFilter(this.props.column, this.state.selectedFilters);
},
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;
return <Menu multiple={true}
9 years ago
prefixCls="ant-dropdown-menu"
className="ant-table-filter-dropdown"
onSelect={this.handleSelectFilter}
onDeselect={this.handleDeselectFilter}
selectedKeys={this.state.selectedFilters}>
{this.renderMenus(column.filters)}
<Menu.Divider />
<Menu.Item disabled>
<a className="ant-table-filter-dropdown-link confirm"
9 years ago
style={{
cursor: 'pointer',
pointerEvents: 'visible'
}}
9 years ago
onClick={this.handleConfirm}>
确定
</a>
<a className="ant-table-filter-dropdown-link clear"
9 years ago
style={{
cursor: 'pointer',
pointerEvents: 'visible'
}}
9 years ago
onClick={this.handleClearFilters}>
清空
</a>
</Menu.Item>
</Menu>;
}
});
9 years ago
export default FilterMenu;