Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 5e8627b

Browse files
committed
fixing number sort
1 parent 97047dc commit 5e8627b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/components/reducers/CustomSortingFn.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,36 @@ const dbfolderColumnSortingFn: (
1414
rowB: Row<RowDataType>,
1515
columnId: string
1616
): number => {
17+
const cellA = rowA.getValue<Literal>(columnId);
18+
const cellB = rowB.getValue<Literal>(columnId);
19+
// Check if a and b are numbers
20+
const aIsNumber = !isNaN(Number(cellA));
21+
const bIsNumber = !isNaN(Number(cellB));
22+
23+
// If both are numbers, compare as numbers
24+
if (aIsNumber && bIsNumber) {
25+
return Number(cellA) - Number(cellB);
26+
}
27+
28+
// If both are strings, compare as strings
1729
const a = ParseService.parseLiteral(
18-
rowA.getValue<Literal>(columnId),
30+
cellA,
1931
InputType.SORTING,
2032
ddbbConfig,
2133
true
2234
)
2335
.toString()
2436
.toLowerCase();
2537
const b = ParseService.parseLiteral(
26-
rowB.getValue<Literal>(columnId),
38+
cellB,
2739
InputType.SORTING,
2840
ddbbConfig,
2941
true
3042
)
3143
.toString()
3244
.toLowerCase();
45+
46+
// String comparison
3347
return a === b ? 0 : a > b ? 1 : -1;
3448
};
3549

0 commit comments

Comments
 (0)