Skip to content

Commit

Permalink
#7085 better sort NaN numbers (#7173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz Jurowicz authored and scottdraves committed Apr 13, 2018
1 parent 3cd7a88 commit c9b0dcd
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions js/notebook/src/tableDisplay/dataGrid/row/RowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,32 @@ export default class RowManager {
this.rows = this.rows.sort((row1, row2) => {
let value1 = columnValueResolver(resolverFn(row1, columnIndex));
let value2 = columnValueResolver(resolverFn(row2, columnIndex));
let result = 0;

if (value1 > value2) {
result = 1;
}

if (value1 < value2) {
result = -1;
}
let result = this.compareSortedValues(value1, value2)

return shouldReverse ? -result : result;
});
}

private compareSortedValues(value1, value2) {
if (
typeof value1 === 'number'
&& typeof value2 === 'number'
&& !isFinite(value1 - value2)
) {
return !isFinite(value1) ? !isFinite(value2) ? 0 : 1 : -1;
}

if (value1 > value2) {
return 1;
}

if (value1 < value2) {
return -1;
}

return 0;
}

resetSorting() {
if (this.sortedBy) {
this.sortedBy.sort(SORT_ORDER.NO_SORT);
Expand Down

0 comments on commit c9b0dcd

Please sign in to comment.