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(sqllab): Floating numbers not sorting correctly in result column #17573

Merged
merged 7 commits into from
Dec 4, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ export default class FilterableTable extends PureComponent<
return (a: Datum, b: Datum) => {
const aValue = a[sortBy];
const bValue = b[sortBy];

// Parse any floating numbers so they'll sort correctly
const parseFloatingNums = (value: any) =>
value.isNan ? value : parseFloat(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's cool, didn't know that isNan was a function!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it's Number.isNan 😅


if (aValue === bValue) {
// equal items sort equally
return 0;
Expand All @@ -337,9 +342,9 @@ export default class FilterableTable extends PureComponent<
return -1;
}
if (descending) {
return aValue < bValue ? 1 : -1;
return parseFloatingNums(aValue) < parseFloatingNums(bValue) ? 1 : -1;
betodealmeida marked this conversation as resolved.
Show resolved Hide resolved
}
return aValue < bValue ? -1 : 1;
return parseFloatingNums(aValue) < parseFloatingNums(bValue) ? -1 : 1;
};
}

Expand Down