Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

persist filter across table refreshes #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build/reactable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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',
Expand Down
14 changes: 13 additions & 1 deletion lib/reactable/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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',
Expand Down
16 changes: 15 additions & 1 deletion src/reactable/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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) {
Expand Down