From 33deeb6e9eab45b245d3296815ee7d635ae3a8c2 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sat, 13 Aug 2022 15:38:21 +0100 Subject: [PATCH] Support filtering data exports to only certain columns with internal tables --- .../server/src/api/controllers/row/internal.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/internal.js b/packages/server/src/api/controllers/row/internal.js index 086e1d9ce4..0c92959db8 100644 --- a/packages/server/src/api/controllers/row/internal.js +++ b/packages/server/src/api/controllers/row/internal.js @@ -375,6 +375,7 @@ exports.exportRows = async ctx => { const table = await db.get(ctx.params.tableId) const rowIds = ctx.request.body.rows let format = ctx.query.format + const { columns } = ctx.request.body let response = ( await db.allDocs({ include_docs: true, @@ -382,7 +383,20 @@ exports.exportRows = async ctx => { }) ).rows.map(row => row.doc) - let rows = await outputProcessing(table, response) + let result = await outputProcessing(table, response) + let rows = [] + + // Filter data to only specified columns if required + if (columns && columns.length) { + for (let i = 0; i < result.length; i++) { + rows[i] = {} + for (let column of columns) { + rows[i][column] = result[i][column] + } + } + } else { + rows = result + } let headers = Object.keys(rows[0]) const exporter = exporters[format]