diff --git a/build/reactable.js b/build/reactable.js index 7671bed2..916ab92a 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -1264,6 +1264,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) { @@ -1286,13 +1291,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', @@ -1358,9 +1370,9 @@ window.ReactDOM["default"] = window.ReactDOM; } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/lib/reactable/table.js b/lib/reactable/table.js index e2235b66..18c76a2e 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', @@ -365,9 +377,9 @@ var Table = (function (_React$Component) { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/src/reactable/table.jsx b/src/reactable/table.jsx index 82601180..37b70bb3 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) { @@ -323,9 +337,9 @@ export class Table extends React.Component { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }.bind(this));