fix: table sorting when units are present (#5249)

This commit is contained in:
Vikrant Gupta 2024-06-17 15:51:04 +05:30 committed by GitHub
parent f1b5da9916
commit 2a4e97f8da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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;