diff --git a/packages/plugins/export/src/server/actions/export-xlsx.ts b/packages/plugins/export/src/server/actions/export-xlsx.ts index 0e5ac882e..a78dbfdc0 100644 --- a/packages/plugins/export/src/server/actions/export-xlsx.ts +++ b/packages/plugins/export/src/server/actions/export-xlsx.ts @@ -10,10 +10,10 @@ export async function exportXlsx(ctx: Context, next: Next) { if (typeof columns === 'string') { columns = JSON.parse(columns); } - const appends = columns2Appends(columns, ctx); - columns = columns?.filter((col) => col?.dataIndex?.length > 0); const repository = ctx.db.getRepository(resourceName, resourceOf) as Repository; const collection = repository.collection; + columns = columns?.filter((col) => collection.hasField(col.dataIndex[0]) && col?.dataIndex?.length > 0); + const appends = columns2Appends(columns, ctx); const data = await repository.find({ filter, fields, diff --git a/packages/plugins/export/src/server/utils/columns2Appends.ts b/packages/plugins/export/src/server/utils/columns2Appends.ts index 7484b8853..6ad119776 100644 --- a/packages/plugins/export/src/server/utils/columns2Appends.ts +++ b/packages/plugins/export/src/server/utils/columns2Appends.ts @@ -6,7 +6,7 @@ export function columns2Appends(columns, ctx) { const appendColumns = []; for (let i = 0, iLen = column.dataIndex.length; i < iLen; i++) { let field = collection.getField(column.dataIndex[i]); - if (field.target) { + if (field?.target) { appendColumns.push(column.dataIndex[i]); collection = ctx.db.getCollection(field.target); }