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

Commit e7372ff

Browse files
committed
fix sorting with nullables
1 parent 128f396 commit e7372ff

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

src/cdm/HeaderActionModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SortedType } from "cdm/DatabaseModel";
21
import { HeaderMenuProps } from "cdm/HeaderModel";
32

43
export type HeaderActionResponse = {

src/components/DefaultHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
5454
const created: boolean = false;
5555
/** Properties of header */
5656
const { column, header, table } = headerProps;
57+
5758
/** Column values */
5859
const { id, dataType, options, position, label, config } =
5960
column.columnDef as TableColumn;

src/components/Table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ import { DndProvider } from "react-dnd";
4646
import { HTML5Backend } from "react-dnd-html5-backend";
4747
import TableCell from "components/TableCell";
4848
import getInitialColumnSizing from "components/behavior/InitialColumnSizeRecord";
49+
import customSortingFn from "components/behavior/CustomSortingFn";
4950

5051
const defaultColumn: Partial<ColumnDef<RowDataType>> = {
5152
minSize: DatabaseLimits.MIN_COLUMN_HEIGHT,
5253
maxSize: DatabaseLimits.MAX_COLUMN_HEIGHT,
5354
cell: DefaultCell,
5455
header: DefaultHeader,
55-
sortingFn: "alphanumeric",
56+
sortingFn: customSortingFn,
5657
};
5758

5859
/**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Row } from "@tanstack/react-table";
2+
import { RowDataType } from "cdm/FolderModel";
3+
4+
function customSortingFn(rowA: Row<RowDataType>, rowB: Row<RowDataType>, columnId: string): number {
5+
const a = rowA.getValue(columnId);
6+
const b = rowB.getValue(columnId);
7+
if (areEqual(a, b)) {
8+
return 0;
9+
}
10+
if (a == null) {
11+
return -1;
12+
}
13+
14+
if (b == null) {
15+
return 1;
16+
}
17+
18+
return fallback(a, b);
19+
}
20+
function areEqual(a: any, b: any): boolean {
21+
// It is necessary?
22+
if (a == null && b == null) {
23+
return true;
24+
}
25+
return a === b;
26+
}
27+
28+
function fallback(a: any, b: any): number {
29+
return isNaN(a)
30+
? a.localeCompare(b)
31+
: a - b;
32+
}
33+
34+
export default customSortingFn;

src/components/portals/CalendarPortal.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
5959
placeholderText="Pick a date..."
6060
/>
6161
) : (
62-
<span
63-
className={`${c("calendar")}`}
64-
onClick={handleOnClick}
65-
placeholder={"Pick a date..."}
66-
>
62+
<span className={`${c("calendar")}`} onClick={handleOnClick}>
6763
{DateTime.isDateTime(calendarState)
6864
? (calendarState as unknown as DateTime).toFormat("yyyy-MM-dd")
6965
: null}

src/components/portals/CalendarTimePortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
4141
};
4242

4343
return column.isMetadata ? (
44-
<span className="calendar-time" placeholder="Pick a datetime">
44+
<span className="calendar-time">
4545
{DateTime.isDateTime(calendarTimeState)
4646
? (calendarTimeState as DateTime).toFormat("yyyy-MM-dd h:mm a")
4747
: null}

0 commit comments

Comments
 (0)