From 233e22b801de58d5fd5dd2af26b23b909bc9a542 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 11 Dec 2020 23:29:57 +0100 Subject: [PATCH] Add numRange filter --- .../customTableFilterFunction.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/app/helperFunctions/customTableFilterFunction.ts b/src/app/helperFunctions/customTableFilterFunction.ts index 3391cdd..c04b447 100644 --- a/src/app/helperFunctions/customTableFilterFunction.ts +++ b/src/app/helperFunctions/customTableFilterFunction.ts @@ -11,6 +11,9 @@ export function customTableFilterFunction(data: any, filter: any) { if (filterElement.type === 'String' || filterElement.type === 'Id') { let searchString = filterElement.value.trim(); let dataElement = data[filterElementName]?.trim(); + if (dataElement == null) { + return false; + } if (!filterElement.options.caseSensitive) { searchString = searchString.toLowerCase(); dataElement = dataElement.toLowerCase(); @@ -41,6 +44,32 @@ export function customTableFilterFunction(data: any, filter: any) { } } } + if (filterElement.type === 'NumRange') { + if ( + filterElement.minValue.min != null || + filterElement.minValue.max != null || + filterElement.maxValue.min != null || + filterElement.maxValue.max != null + ) { + let dataElementMin = data[filterElementName + '.min']; + let dataElementMax = data[filterElementName + '.max']; + if (dataElementMin == null && dataElementMax == null) { + return false; + } + if (filterElement.minValue.min != null && dataElementMin < filterElement.minValue.min) { + return false; + } + if (filterElement.minValue.max != null && dataElementMin > filterElement.minValue.max) { + return false; + } + if (filterElement.maxValue.min != null && dataElementMax < filterElement.maxValue.min) { + return false; + } + if (filterElement.maxValue.max != null && dataElementMax > filterElement.maxValue.max) { + return false; + } + } + } } /*const b = !filter.includesString ||