diff options
Diffstat (limited to 'src/components/Mixins')
-rw-r--r-- | src/components/Mixins/TableFilterMixin.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/components/Mixins/TableFilterMixin.js b/src/components/Mixins/TableFilterMixin.js index 25c7497a..58e70c57 100644 --- a/src/components/Mixins/TableFilterMixin.js +++ b/src/components/Mixins/TableFilterMixin.js @@ -16,6 +16,25 @@ const TableFilterMixin = { } return returnRow; }); + }, + getFilteredTableDataByDate( + tableData = [], + startDate, + endDate, + propertyKey = 'date' + ) { + if (!startDate && !endDate) return tableData; + const startDateInMs = startDate ? startDate.getTime() : 0; + const endDateInMs = endDate + ? endDate.getTime() + : Number.POSITIVE_INFINITY; + return tableData.filter(row => { + const date = row[propertyKey]; + if (!(date instanceof Date)) return; + + const dateInMs = date.getTime(); + if (dateInMs >= startDateInMs && dateInMs <= endDateInMs) return row; + }); } } }; |