Skip to content

Commit

Permalink
fix(sort): support empty strings when sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Liverant authored and shlomiassaf committed May 19, 2021
1 parent 20e1e61 commit 6a1023e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libs/ngrid/core/src/lib/data-source/triggers/sort/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ export function applySort<T>(column: PblColumnDefinition, sort: PblNgridSortDefi

function defaultSorter<T>(column: PblColumnDefinition, sort: PblNgridSortInstructions, data: T[]): T[] {
return data.sort((a, b) => {
const directionMultiplier = (sort.order === 'asc' ? 1 : -1);
let valueA = getValue(column, a);
let valueB = getValue(column, b);

valueA = isNaN(+valueA) ? valueA : +valueA;
valueB = isNaN(+valueB) ? valueB : +valueB;

return (valueA < valueB ? -1 : valueA === valueB ? 0 : 1) * (sort.order === 'asc' ? 1 : -1);
if (valueA && valueB) {
return (valueA < valueB ? -1 : valueA === valueB ? 0 : 1) * directionMultiplier;
}

return (valueA ? 1 : -1) * directionMultiplier;
});
}

0 comments on commit 6a1023e

Please sign in to comment.