fix empty filters when receive new columns in Table, ref #418 comment-163093580

This commit is contained in:
afc163 2015-12-09 15:59:54 +08:00
parent 801330cac7
commit dfd70ae634

View File

@ -124,11 +124,6 @@ let AntTable = React.createClass({
loading: true
}, this.fetch);
}
if (nextProps.columns !== this.props.columns) {
this.setState({
filters: {}
});
}
if ('loading' in nextProps) {
this.setState({
loading: nextProps.loading
@ -191,6 +186,13 @@ let AntTable = React.createClass({
filters = objectAssign({}, this.state.filters, {
[this.getColumnKey(column)]: filters
});
// Remove filters not in current columns
const currentColumnKeys = this.props.columns.map(c => this.getColumnKey(c));
Object.keys(filters).forEach((columnKey) => {
if (currentColumnKeys.indexOf(columnKey) < 0) {
delete filters[columnKey];
}
});
const newState = {
selectedRowKeys: [],
selectionDirty: false,
@ -480,16 +482,9 @@ let AntTable = React.createClass({
prepareParamsArguments(state) {
//
let pagination;
let filters = {};
let sorter = {};
pagination = state.pagination;
this.props.columns.forEach((column) => {
let colFilters = state.filters[this.getColumnKey(column)] || [];
if (colFilters.length > 0) {
filters[this.getColumnKey(column)] = colFilters;
}
});
const pagination = state.pagination;
const filters = state.filters;
const sorter = {};
if (state.sortColumn &&
state.sortOrder &&
state.sortColumn.dataIndex) {
@ -591,6 +586,9 @@ let AntTable = React.createClass({
if (state.filters) {
Object.keys(state.filters).forEach((columnKey) => {
let col = this.findColumn(columnKey);
if (!col) {
return;
}
let values = state.filters[columnKey] || [];
if (values.length === 0) {
return;