diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 0b17a35772..62d81fb29e 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -8,7 +8,6 @@ import { gridSocket } from "../../../websockets" import sdk from "../../../sdk" import * as exporters from "../view/exporters" import { apiFileReturn } from "../../../utilities/fileSystem" -import _ from "lodash" function pickApi(tableId: any) { if (isExternalTable(tableId)) { @@ -156,7 +155,7 @@ export async function searchView(ctx: Ctx) { } ctx.status = 200 - let { rows } = await quotas.addQuery( + const { rows } = await quotas.addQuery( () => sdk.rows.search({ tableId: view.tableId, @@ -164,17 +163,13 @@ export async function searchView(ctx: Ctx) { sort: view.sort?.field, sortOrder: view.sort?.order, sortType: view.sort?.type, + fields: view.columns, }), { datasourceId: view.tableId, } ) - const { columns } = view - if (columns) { - rows = rows.map(r => _.pick(r, columns)) - } - ctx.body = { rows } } diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index 53f3bbbc43..ab0723ab10 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -3,6 +3,7 @@ import { isExternalTable } from "../../../integrations/utils" import * as internal from "./search/internal" import * as external from "./search/external" import { Format } from "../../../api/controllers/view/exporters" +import _ from "lodash" export interface SearchParams { tableId: string @@ -15,6 +16,7 @@ export interface SearchParams { sortType?: SortType version?: string disableEscaping?: boolean + fields?: string[] } export interface ViewParams { @@ -33,7 +35,12 @@ function pickApi(tableId: any) { export async function search(options: SearchParams): Promise<{ rows: any[] }> { - return pickApi(options.tableId).search(options) + let { rows } = await pickApi(options.tableId).search(options) + + if (options.fields) { + rows = rows.map((r: any) => _.pick(r, options.fields!)) + } + return { rows } } export interface ExportRowsParams {