export onFilter function to allow user to access

This commit is contained in:
Chun-MingChen
2018-04-01 13:51:11 +08:00
parent a1477e2ad3
commit 4dd39aeed8
3 changed files with 41 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
/* eslint react/require-default-props: 0 */
/* eslint no-return-assign: 0 */
import React, { Component } from 'react';
@@ -30,12 +31,23 @@ class NumberFilter extends Component {
}
componentDidMount() {
const { column, onFilter } = this.props;
const { column, onFilter, getFilterBy } = this.props;
const comparator = this.numberFilterComparator.value;
const number = this.numberFilter.value;
if (comparator && number) {
onFilter(column, FILTER_TYPE.NUMBER)({ number, comparator });
}
// export onFilter function to allow users to access
if (getFilterBy) {
getFilterBy((filterVal) => {
this.setState(() => ({ isSelected: (filterVal !== '') }));
onFilter(column, FILTER_TYPE.NUMBER)({
number: filterVal.number,
comparator: filterVal.comparator
});
});
}
}
componentWillUnmount() {
@@ -224,7 +236,8 @@ NumberFilter.propTypes = {
comparatorStyle: PropTypes.object,
comparatorClassName: PropTypes.string,
numberStyle: PropTypes.object,
numberClassName: PropTypes.string
numberClassName: PropTypes.string,
getFilterBy: PropTypes.func
};
NumberFilter.defaultProps = {

View File

@@ -25,9 +25,19 @@ class SelectFilter extends Component {
}
componentDidMount() {
const { column, onFilter, getFilterBy } = this.props;
const value = this.selectInput.value;
if (value && value !== '') {
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
onFilter(column, FILTER_TYPE.SELECT)(value);
}
// export onFilter function to allow users to access
if (getFilterBy) {
getFilterBy((filterVal) => {
this.setState(() => ({ isSelected: filterVal !== '' }));
onFilter(column, FILTER_TYPE.SELECT)(filterVal);
});
}
}
@@ -90,6 +100,7 @@ class SelectFilter extends Component {
comparator,
withoutEmptyOption,
caseSensitive,
getFilterBy,
...rest
} = this.props;
@@ -121,7 +132,8 @@ SelectFilter.propTypes = {
className: PropTypes.string,
withoutEmptyOption: PropTypes.bool,
defaultValue: PropTypes.any,
caseSensitive: PropTypes.bool
caseSensitive: PropTypes.bool,
getFilterBy: PropTypes.func
};
SelectFilter.defaultProps = {

View File

@@ -19,13 +19,20 @@ class TextFilter extends Component {
}
componentDidMount() {
const { onFilter } = this.props;
const { onFilter, getFilterBy, column } = this.props;
const defaultValue = this.input.value;
if (defaultValue) {
onFilter(this.props.column, FILTER_TYPE.TEXT)(defaultValue);
}
// export onFilter function to allow users to access
if (getFilterBy) {
getFilterBy((filterVal) => {
this.setState(() => ({ value: filterVal }));
onFilter(column, FILTER_TYPE.TEXT)(filterVal);
});
}
}
componentWillReceiveProps(nextProps) {
@@ -81,6 +88,7 @@ class TextFilter extends Component {
onFilter,
caseSensitive,
defaultValue,
getFilterBy,
...rest
} = this.props;
@@ -110,7 +118,8 @@ TextFilter.propTypes = {
placeholder: PropTypes.string,
style: PropTypes.object,
className: PropTypes.string,
caseSensitive: PropTypes.bool
caseSensitive: PropTypes.bool,
getFilterBy: PropTypes.func
};
TextFilter.defaultProps = {