From 1f0464948b786e60a46b17ff2c10442cead22724 Mon Sep 17 00:00:00 2001 From: Jared Chavez Date: Thu, 13 Oct 2016 14:45:07 -0700 Subject: [PATCH] persist filter across table refreshes --- build/reactable.js | 14 +++++++++++++- lib/reactable/table.js | 14 +++++++++++++- src/reactable/table.jsx | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/build/reactable.js b/build/reactable.js index 92b762b5..55c62ab0 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -1257,6 +1257,11 @@ window.ReactDOM["default"] = window.ReactDOM; }; } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'updateCurrentSort', value: function updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && sortBy.direction !== this.state.currentSort.direction) { @@ -1279,13 +1284,20 @@ window.ReactDOM["default"] = window.ReactDOM; this.filterBy(this.props.filterBy); } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage); this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + var filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } }, { key: 'applyFilter', diff --git a/lib/reactable/table.js b/lib/reactable/table.js index e2235b66..0cc430da 100644 --- a/lib/reactable/table.js +++ b/lib/reactable/table.js @@ -271,6 +271,11 @@ var Table = (function (_React$Component) { }; } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'updateCurrentSort', value: function updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && sortBy.direction !== this.state.currentSort.direction) { @@ -293,13 +298,20 @@ var Table = (function (_React$Component) { this.filterBy(this.props.filterBy); } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage); this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + var filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } }, { key: 'applyFilter', diff --git a/src/reactable/table.jsx b/src/reactable/table.jsx index 82601180..ef401639 100644 --- a/src/reactable/table.jsx +++ b/src/reactable/table.jsx @@ -230,6 +230,12 @@ export class Table extends React.Component { }; } + getCurrentFilter(propFilter) { + return (this.state.filter !== undefined && propFilter === '') ? + this.state.filter : + propFilter; + } + updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && @@ -251,12 +257,20 @@ export class Table extends React.Component { this.filterBy(this.props.filterBy); } + getCurrentFilter(propFilter) { + return (this.state.filter !== undefined && propFilter === '') ? + this.state.filter : + propFilter; + } + componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage) this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + let filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } applyFilter(filter, children) {