From 2a4e97f8da412de99086d599840c59ef13a3ca61 Mon Sep 17 00:00:00 2001 From: Vikrant Gupta Date: Mon, 17 Jun 2024 15:51:04 +0530 Subject: [PATCH] fix: table sorting when units are present (#5249) --- frontend/src/container/GridTableComponent/index.tsx | 4 ++-- frontend/src/lib/query/createTableColumnsFromQuery.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/container/GridTableComponent/index.tsx b/frontend/src/container/GridTableComponent/index.tsx index 26bdda1a49..171f09da07 100644 --- a/frontend/src/container/GridTableComponent/index.tsx +++ b/frontend/src/container/GridTableComponent/index.tsx @@ -62,10 +62,11 @@ function GridTableComponent({ mutateDataSource = mutateDataSource.map( (val): RowData => { - const newValue = val; + const newValue = { ...val }; Object.keys(val).forEach((k) => { if (columnUnits[k]) { newValue[k] = getYAxisFormattedValue(String(val[k]), columnUnits[k]); + newValue[`${k}_without_unit`] = val[k]; } }); return newValue; @@ -81,7 +82,6 @@ function GridTableComponent({ applyColumnUnits, originalDataSource, ]); - useEffect(() => { if (tableProcessedDataRef) { // eslint-disable-next-line no-param-reassign diff --git a/frontend/src/lib/query/createTableColumnsFromQuery.ts b/frontend/src/lib/query/createTableColumnsFromQuery.ts index 28b5b3dc67..c3a5865cd9 100644 --- a/frontend/src/lib/query/createTableColumnsFromQuery.ts +++ b/frontend/src/lib/query/createTableColumnsFromQuery.ts @@ -537,8 +537,12 @@ const generateTableColumns = ( width: QUERY_TABLE_CONFIG.width, render: renderColumnCell && renderColumnCell[item.dataIndex], sorter: (a: RowData, b: RowData): number => { - const valueA = Number(a[item.dataIndex]); - const valueB = Number(b[item.dataIndex]); + const valueA = Number( + a[`${item.dataIndex}_without_unit`] ?? a[item.dataIndex], + ); + const valueB = Number( + b[`${item.dataIndex}_without_unit`] ?? b[item.dataIndex], + ); if (!isNaN(valueA) && !isNaN(valueB)) { return valueA - valueB;