From 11dd5fc805a372ea661cc7e58ac881293f7196f4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 30 Mar 2023 16:23:13 +0100 Subject: [PATCH] Sort columns to put autocolumns last --- .../src/components/sheet/stores/columns.js | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/frontend-core/src/components/sheet/stores/columns.js b/packages/frontend-core/src/components/sheet/stores/columns.js index ae2283a8de..47cc56e012 100644 --- a/packages/frontend-core/src/components/sheet/stores/columns.js +++ b/packages/frontend-core/src/components/sheet/stores/columns.js @@ -63,20 +63,30 @@ export const createColumnsStores = context => { // Update columns, removing extraneous columns and adding missing ones columns.set( - fields.map(field => { - // Check if there is an existing column with this name so we can keep - // the width setting - let existing = currentColumns.find(x => x.name === field) - if (!existing && currentStickyColumn?.name === field) { - existing = currentStickyColumn - } - return { - name: field, - width: existing?.width || DefaultColumnWidth, - schema: schema[field], - visible: existing?.visible ?? true, - } - }) + fields + .map(field => { + // Check if there is an existing column with this name so we can keep + // the width setting + let existing = currentColumns.find(x => x.name === field) + if (!existing && currentStickyColumn?.name === field) { + existing = currentStickyColumn + } + return { + name: field, + width: existing?.width || DefaultColumnWidth, + schema: schema[field], + visible: existing?.visible ?? true, + } + }) + .sort((a, b) => { + // Sort columns to put auto columns last + let autoColA = a.schema?.autocolumn + let autoColB = b.schema?.autocolumn + if (autoColA === autoColB) { + return 0 + } + return autoColA ? 1 : -1 + }) ) // Update sticky column