From 0ff91b4135a8d71a5ec930874d6032b2b096007f Mon Sep 17 00:00:00 2001 From: Leon Shi Date: Tue, 17 May 2016 10:58:01 +0800 Subject: [PATCH] Fix Table pagination after filter, close #1669 (#1715) --- components/table/index.jsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/components/table/index.jsx b/components/table/index.jsx index 2458f829c6..0a9fadc8b4 100644 --- a/components/table/index.jsx +++ b/components/table/index.jsx @@ -248,20 +248,27 @@ export default class Table extends React.Component { } handleFilter = (column, nextFilters) => { + const props = this.props; + let pagination = { ...this.state.pagination }; const filters = { ...this.state.filters, [this.getColumnKey(column)]: nextFilters, }; // Remove filters not in current columns - const currentColumnKeys = this.props.columns.map(c => this.getColumnKey(c)); + const currentColumnKeys = props.columns.map(c => this.getColumnKey(c)); Object.keys(filters).forEach((columnKey) => { if (currentColumnKeys.indexOf(columnKey) < 0) { delete filters[columnKey]; } }); + // Reset current prop + pagination.current = 1; + pagination.onChange(pagination.current); + const newState = { selectionDirty: false, + pagination, }; const filtersToSetState = { ...filters }; // Remove filters which is controlled @@ -274,9 +281,21 @@ export default class Table extends React.Component { if (Object.keys(filtersToSetState).length > 0) { newState.filters = filtersToSetState; } + + // Controlled current prop will not respond user interaction + if (props.pagination && 'current' in props.pagination) { + newState.pagination = { + ...pagination, + current: this.state.pagination.current, + }; + } + this.setState(newState, () => { - this.props.onChange(...this.prepareParamsArguments({ - ...this.state, selectionDirty: false, filters, + props.onChange(...this.prepareParamsArguments({ + ...this.state, + selectionDirty: false, + filters, + pagination, })); }); }