Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: table sorting when units are present #5249

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/container/GridTableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
vikrantgupta25 marked this conversation as resolved.
Show resolved Hide resolved
}
});
return newValue;
Expand All @@ -81,7 +82,6 @@ function GridTableComponent({
applyColumnUnits,
originalDataSource,
]);

useEffect(() => {
if (tableProcessedDataRef) {
// eslint-disable-next-line no-param-reassign
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/lib/query/createTableColumnsFromQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading