Skip to content

Commit

Permalink
Fix filters on dynamic columns update
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Blin committed Sep 5, 2017
1 parent 3999f71 commit 84cc76c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class BootstrapTable extends Component {
}

initTable(props) {
// If columns changed, clean removed columns that had filters
if (props.children !== this.props.children && this.filter) {
const nextDataFields = props.children.map(column => column.props.dataField);
this.props.children.forEach(column => {
const { dataField, filter } = column.props;
if (!nextDataFields.includes(dataField)) {
// Clear filter
this.filter.handleFilter(dataField, '', filter.type, filter);
}
});
}

let { keyField } = props;

const isKeyFieldDefined = typeof keyField === 'string' && keyField.length;
Expand Down
13 changes: 13 additions & 0 deletions src/TableHeaderColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class TableHeaderColumn extends Component {
if (nextProps.reset) {
this.cleanFiltered();
}

// If column not displaying the same dataField, reset the filter accordingly
if (nextProps.dataField !== this.props.dataField) {
const emitter = nextProps.filter.emitter || {};
const currentFilter = emitter.currentFilter || {};
const filter = currentFilter[nextProps.dataField];
const value = filter ? filter.value : '';

const { ref } = this.getFilters() || {};
if (this.refs[ref]) {
this.refs[ref].setState({ value });
}
}
}

handleColumnClick = () => {
Expand Down

0 comments on commit 84cc76c

Please sign in to comment.