From fd89d123660f37db2cceb6ac12eb3cfb3261fbf7 Mon Sep 17 00:00:00 2001 From: wisonic-s <51065359+wisonic-s@users.noreply.github.com> Date: Tue, 24 Jun 2025 08:54:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=80=8F=E8=A7=86=E8=A1=A8=E6=8C=87=E6=A0=87=E5=9C=A8=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AD=97=E6=AE=B5=E6=97=B6=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/table/table-pivot.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts index 8979613af8..aef198e3e7 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts @@ -301,7 +301,14 @@ export class TablePivot extends S2ChartView { if (sortMethod === 'CUSTOM_SORT') { sort.sortBy = valueFieldMap[f].customSort } else { - if (i === 0) { + if ([2, 3, 4].includes(valueFieldMap[f]?.deType)) { + const fieldValues = newData.map(item => item[f]) + const uniqueValues = [...new Set(fieldValues)] + uniqueValues.sort((a, b) => { + return sortMethod === 'ASC' ? a - b : b - a + }) + sort.sortBy = uniqueValues + } else if (i === 0) { sort.sortMethod = sortMethod } else { const fieldValues = newData.map(item => item[f]) @@ -309,9 +316,6 @@ export class TablePivot extends S2ChartView { // 根据配置动态决定排序顺序 uniqueValues.sort((a, b) => { - if ([2, 3, 4].includes(valueFieldMap[f]?.deType)) { - return sortMethod === 'ASC' ? a - b : b - a - } if (!a && !b) { return 0 } @@ -341,16 +345,20 @@ export class TablePivot extends S2ChartView { if (sortMethod === 'CUSTOM_SORT') { sort.sortBy = valueFieldMap[f].customSort } else { - if (i === 0) { + if ([2, 3, 4].includes(valueFieldMap[f]?.deType)) { + const fieldValues = newData.map(item => item[f]) + const uniqueValues = [...new Set(fieldValues)] + uniqueValues.sort((a, b) => { + return sortMethod === 'ASC' ? a - b : b - a + }) + sort.sortBy = uniqueValues + } else if (i === 0) { sort.sortMethod = sortMethod } else { const fieldValues = newData.map(item => item[f]) const uniqueValues = [...new Set(fieldValues)] // 根据配置动态决定排序顺序 uniqueValues.sort((a, b) => { - if ([2, 3, 4].includes(valueFieldMap[f]?.deType)) { - return sortMethod === 'ASC' ? a - b : b - a - } if (!a && !b) { return 0 }