From b3e87092725e6d5ade9e2602fb898f36a1dde7b3 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 24 Aug 2026 22:53:11 +0000 Subject: [PATCH] feat(grid): show average for numeric selections Closes #4929 --- apps/desktop/src/components/grid/DataGrid.vue | 17 +++--- .../components/grid/DataGridPagination.vue | 2 + .../grid/__tests__/DataGridSurfaces.spec.ts | 42 +++++++++++++++ apps/desktop/src/i18n/locales/en.ts | 1 + apps/desktop/src/i18n/locales/es.ts | 1 + apps/desktop/src/i18n/locales/it.ts | 1 + apps/desktop/src/i18n/locales/ja.ts | 1 + apps/desktop/src/i18n/locales/ko.ts | 1 + apps/desktop/src/i18n/locales/pt-BR.ts | 1 + apps/desktop/src/i18n/locales/zh-CN.ts | 1 + apps/desktop/src/i18n/locales/zh-TW.ts | 1 + .../__tests__/dataGrid/gridSelection.spec.ts | 53 ++++++++++++++++++- .../desktop/src/lib/dataGrid/gridSelection.ts | 21 ++++++++ 13 files changed, 133 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index dfb82fae09..1b0076f1a8 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -253,7 +253,7 @@ import { allNullColumnIndexes } from "@/lib/dataGrid/dataGridColumnVisibility"; import { buildDataGridColumnLookupItems, dataGridColumnCommentFor, filterDataGridColumnLookupItems } from "@/lib/dataGrid/dataGridColumnLookup"; import { uniqueDataGridColumnOrderKeys } from "@/lib/dataGrid/dataGridColumnOrder"; import { dataGridColumnLayoutScopeKey, TABLE_DATA_GRID_COLUMN_ORDER_CHANGED_EVENT, tableDataGridColumnOrderScopeKey } from "@/lib/dataGrid/dataGridColumnLayoutStorage"; -import { summarizeSelection } from "@/lib/dataGrid/gridSelection"; +import { createPendingSelectionSummary, formatSelectionAggregate, formatSelectionAverage, summarizeSelection } from "@/lib/dataGrid/gridSelection"; import { captureDataGridSelection, restoreDataGridSelection, type CaptureDataGridSelectionOptions, type PersistedDataGridSelection } from "@/lib/dataGrid/dataGridSelectionPersistence"; import { dataGridFrameCoversRow, dataGridSelectionEdgeMask, dataGridSelectionFrameKindAtCell, dataGridSelectionUsesOuterFrame, resolveDataGridSelectionFrames } from "@/lib/dataGrid/dataGridSelectionFrames"; import { @@ -5554,12 +5554,7 @@ const multiRowCount = computed(() => { const selectionSummary = computed(() => { if (!hasCellSelection.value) return null; if (isSelectingCells.value) { - return { - cellCount: selectedCellCount.value, - rowCount: multiRowCount.value, - numericCount: 0, - sum: 0, - }; + return createPendingSelectionSummary(selectedCellCount.value, multiRowCount.value); } return summarizeSelection(selectedCells.value); }); @@ -5567,8 +5562,11 @@ const selectionSummarySumText = computed(() => { if (isSelectingCells.value) return "…"; const summary = selectionSummary.value; if (!summary) return "0"; - const sum = Object.is(summary.sum, -0) ? 0 : summary.sum; - return Number.isInteger(sum) ? String(sum) : sum.toLocaleString(undefined, { maximumFractionDigits: 12 }); + return formatSelectionAggregate(summary.sum); +}); +const selectionSummaryAverageText = computed(() => { + if (isSelectingCells.value) return "…"; + return formatSelectionAverage(selectionSummary.value?.average); }); const isMultiRow = computed(() => multiRowCount.value > 1); @@ -13587,6 +13585,7 @@ function currentGridContextMenuItems(): ContextMenuItem[] { :pagination-enabled="paginationEnabled" :selection-summary="selectionSummary" :selection-summary-sum-text="selectionSummarySumText" + :selection-summary-average-text="selectionSummaryAverageText" :loading="gridPaginationBusy" :infinite-scroll-enabled="infiniteScrollEnabled" :infinite-scroll-all-loaded="infiniteScrollAllLoaded" diff --git a/apps/desktop/src/components/grid/DataGridPagination.vue b/apps/desktop/src/components/grid/DataGridPagination.vue index ca1142c91c..1c4651e5e0 100644 --- a/apps/desktop/src/components/grid/DataGridPagination.vue +++ b/apps/desktop/src/components/grid/DataGridPagination.vue @@ -16,6 +16,7 @@ const props = withDefaults( paginationEnabled?: boolean; selectionSummary: { cellCount: number; rowCount: number } | null; selectionSummarySumText: string; + selectionSummaryAverageText: string; loading: boolean; infiniteScrollEnabled: boolean; infiniteScrollAllLoaded: boolean; @@ -86,6 +87,7 @@ function handlePageInputKeydown(event: KeyboardEvent) {