Skip to content

Commit

Permalink
[fix] place null values at the end when sorting table (keplergl#2391)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <[email protected]>
Co-authored-by: Rui Wang <[email protected]>
  • Loading branch information
igorDykhta and albatross97 authored Oct 23, 2023
1 parent 4f51abc commit f1e654d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/table/src/kepler-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ import {
getLogDomain,
getOrdinalDomain,
getQuantileDomain,
DataContainerInterface
DataContainerInterface,
notNullorUndefined
} from '@kepler.gl/utils';

export type GpuFilter = {
Expand Down Expand Up @@ -583,11 +584,16 @@ export function sortDatasetByColumn(
}

const sortFunction = sortBy === SORT_ORDER.ASCENDING ? ascending : descending;
const sortOrder = allIndexes
.slice()
.sort((a, b) =>
sortFunction(dataContainer.valueAt(a, fieldIndex), dataContainer.valueAt(b, fieldIndex))
);
const sortOrder = allIndexes.slice().sort((a, b) => {
const value1 = dataContainer.valueAt(a, fieldIndex);
const value2 = dataContainer.valueAt(b, fieldIndex);
if (!notNullorUndefined(value1) && notNullorUndefined(value2)) {
return 1;
} else if (notNullorUndefined(value1) && !notNullorUndefined(value2)) {
return -1;
}
return sortFunction(value1, value2);
});

dataset.sortColumn = {
[column]: sortBy
Expand Down

0 comments on commit f1e654d

Please sign in to comment.