diff --git a/app/client/components/BaseView.js b/app/client/components/BaseView.js index 4a11daf1..25a02679 100644 --- a/app/client/components/BaseView.js +++ b/app/client/components/BaseView.js @@ -319,8 +319,13 @@ BaseView.prototype.filterByThisCellValue = function() { // ChoiceList and Reflist values get 'flattened' out so we filter by each element within. // In any other column type, complex values (even lists) get converted to JSON. let filterValues; - if (gristTypes.isList(value) && gristTypes.isListType(col.type.peek())) { + const colType = col.type.peek(); + if (gristTypes.isList(value) && gristTypes.isListType(colType)) { filterValues = value.slice(1); + if (!filterValues.length) { + // If the list is empty, filter instead by an empty value for the whole list + filterValues = [colType === "ChoiceList" ? "" : null]; + } } else { if (Array.isArray(value)) { value = JSON.stringify(value); diff --git a/app/client/ui/ColumnFilterMenu.ts b/app/client/ui/ColumnFilterMenu.ts index df905b04..d4e4e1e0 100644 --- a/app/client/ui/ColumnFilterMenu.ts +++ b/app/client/ui/ColumnFilterMenu.ts @@ -496,6 +496,10 @@ function addCountsToMap(valueMap: Map, rowIds: RowId[], // If row contains a list and the column is a Choice List, treat each choice as a separate key if (isList(key) && (columnType === 'ChoiceList')) { const list = decodeObject(key) as unknown[]; + if (!list.length) { + // If the list is empty, add an item for the whole list, otherwise the row will be missing from filters. + addSingleCountToMap(valueMap, '', () => '', () => '', areHiddenRows); + } for (const item of list) { addSingleCountToMap(valueMap, item, () => item, () => item, areHiddenRows); } @@ -505,6 +509,10 @@ function addCountsToMap(valueMap: Map, rowIds: RowId[], // If row contains a Reference List, treat each reference as a separate key if (isList(key) && isRefListType(columnType)) { const refIds = decodeObject(key) as unknown[]; + if (!refIds.length) { + // If the list is empty, add an item for the whole list, otherwise the row will be missing from filters. + addSingleCountToMap(valueMap, null, () => null, () => null, areHiddenRows); + } const refLabels = labelMapFunc(rowId); const displayValues = valueMapFunc(rowId); refIds.forEach((id, i) => { diff --git a/app/common/ColumnFilterFunc.ts b/app/common/ColumnFilterFunc.ts index 03607fff..cbb9cc9e 100644 --- a/app/common/ColumnFilterFunc.ts +++ b/app/common/ColumnFilterFunc.ts @@ -35,7 +35,11 @@ export function makeFilterFunc(state: FilterState, return (val: CellValue) => { if (isList(val) && columnType && isListType(columnType)) { const list = decodeObject(val) as unknown[]; - return list.some(item => values.has(item as any) === include); + if (list.length) { + return list.some(item => values.has(item as any) === include); + } + // If the list is empty, filter instead by an empty value for the whole list + val = columnType === "ChoiceList" ? "" : null; } return (values.has(Array.isArray(val) ? JSON.stringify(val) : val) === include); };