From 0760917a4b54bf6629a5c08d02201407797d00bf Mon Sep 17 00:00:00 2001 From: Vikrant Gupta Date: Fri, 31 May 2024 13:52:07 +0530 Subject: [PATCH] feat: enale temporary sorting on table panel type (#5114) --- .../src/lib/query/createTableColumnsFromQuery.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/query/createTableColumnsFromQuery.ts b/frontend/src/lib/query/createTableColumnsFromQuery.ts index 988b5feae8..85b876dc11 100644 --- a/frontend/src/lib/query/createTableColumnsFromQuery.ts +++ b/frontend/src/lib/query/createTableColumnsFromQuery.ts @@ -7,7 +7,7 @@ import { import { FORMULA_REGEXP } from 'constants/regExp'; import { QUERY_TABLE_CONFIG } from 'container/QueryTable/config'; import { QueryTableProps } from 'container/QueryTable/QueryTable.intefaces'; -import { isEqual, isObject } from 'lodash-es'; +import { isEqual, isNaN, isObject } from 'lodash-es'; import { ReactNode } from 'react'; import { IBuilderFormula, @@ -460,6 +460,18 @@ const generateTableColumns = ( title: item.title, 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]); + + if (!isNaN(valueA) && !isNaN(valueB)) { + return valueA - valueB; + } + + return ((a[item.dataIndex] as string) || '').localeCompare( + (b[item.dataIndex] as string) || '', + ); + }, }; return [...acc, column];