From 6522f6d964a0df32a2f4ec43270a33cba6357292 Mon Sep 17 00:00:00 2001 From: Benny Johnson Date: Tue, 24 Jul 2018 23:20:35 -0400 Subject: [PATCH] Commented out a check which caused the date filter to not update the (#425) table when the date or date comparator were cleared Modified applyFilter in date.js so that it doesn't try to parse an Invalid Date. It was parsing an empty string, which caused it to pass through an invalid date to onFilter, and this wasn't being checked for properly by the onFilter function. It now checks for the empty string and passes in null, which is what the onFilter function was actually checking for --- .../src/components/date.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-bootstrap-table2-filter/src/components/date.js b/packages/react-bootstrap-table2-filter/src/components/date.js index 02468aa..8e31724 100644 --- a/packages/react-bootstrap-table2-filter/src/components/date.js +++ b/packages/react-bootstrap-table2-filter/src/components/date.js @@ -93,12 +93,16 @@ class DateFilter extends Component { } applyFilter(value, comparator) { - if (!comparator || !value) { - return; - } + // if (!comparator || !value) { + // return; + // } const { column, onFilter, delay } = this.props; const execute = () => { - const date = typeof value !== 'object' ? new Date(value) : value; + // Incoming value should always be a string, and the defaultDate + // above is implemented as an empty string, so we can just check for that. + // instead of parsing an invalid Date. The filter function will interpret + // null as an empty date field + const date = value === '' ? null : new Date(value); onFilter(column, FILTER_TYPE.DATE)({ date, comparator }); }; if (delay) {