diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 08690540ce..26deeac2d7 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2334,8 +2334,7 @@ class BaseModelSqlv2 { args: { groupColumnId: string; ignoreFilterSort?: boolean; - sortArr?: any; - filterArr?: any; + options?: (string | number | null | boolean)[]; } & Partial ): Promise< { @@ -2355,7 +2354,9 @@ class BaseModelSqlv2 { // extract distinct group column values let groupingValues; - if (column.uidt === UITypes.SingleSelect) { + if (args.options?.length) { + groupingValues = args.options; + } else if (column.uidt === UITypes.SingleSelect) { const colOptions = await column.getColOptions< SelectOption[] & { options } >(); @@ -2474,9 +2475,9 @@ class BaseModelSqlv2 { const groupedResult: Record[]> = _.groupBy(result, column.title); - const r = Object.entries(groupedResult).map(([key, value]) => ({ + const r = groupingValues.map((key) => ({ key, - value, + value: groupedResult[key] ?? [], })); return r; diff --git a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts index 81e403b0fe..ee40b0786e 100644 --- a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts +++ b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts @@ -246,6 +246,9 @@ async function getGroupedDataList(model, view: View, req) { try { listArgs.sortArr = JSON.parse(listArgs.sortArrJson); } catch (e) {} + try { + listArgs.options = JSON.parse(listArgs.optionsArrJson); + } catch (e) {} let data = []; // let count = 0 @@ -266,13 +269,13 @@ async function getGroupedDataList(model, view: View, req) { }); data = data.map((item) => { // todo: use map to avoid loop - const count = countArr.find( - (countItem) => countItem.key || 'null' === item.key - )?.count; + const count = + countArr.find((countItem) => countItem.key || 'null' === item.key) + ?.count ?? 0; item.value = new PagedResponseImpl(item.value, { ...req.query, - count, + count: count, }); return item; });