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

Commit 921a91f

Browse files
committed
customsortingFn
1 parent 47a42af commit 921a91f

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/components/Table.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ import Select, { OnChangeValue } from "react-select";
4141
import TableRow from "components/TableRow";
4242
import getInitialColumnSizing from "components/behavior/InitialColumnSizeRecord";
4343
import { globalDatabaseFilterFn } from "components/reducers/TableFilterFlavours";
44+
import dbfolderColumnSortingFn from "./reducers/CustomSortingFn";
4445

4546
const defaultColumn: Partial<ColumnDef<RowDataType>> = {
4647
minSize: DatabaseLimits.MIN_COLUMN_HEIGHT,
4748
maxSize: DatabaseLimits.MAX_COLUMN_HEIGHT,
4849
cell: DefaultCell,
4950
header: DefaultHeader,
5051
enableResizing: true,
51-
sortingFn: "auto",
5252
};
5353

5454
/**
@@ -242,7 +242,10 @@ export function Table(tableData: TableDataType) {
242242
tableState: tableStore,
243243
view: view,
244244
},
245-
defaultColumn: defaultColumn,
245+
defaultColumn: {
246+
...defaultColumn,
247+
sortingFn: dbfolderColumnSortingFn(configInfo.getLocalSettings()),
248+
},
246249
getExpandedRowModel: getExpandedRowModel(),
247250
getCoreRowModel: getCoreRowModel(),
248251
getSortedRowModel: getSortedRowModel(),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Row, SortingFn } from "@tanstack/react-table";
2+
import { RowDataType } from "cdm/FolderModel";
3+
import { LocalSettings } from "cdm/SettingsModel";
4+
import { InputType } from "helpers/Constants";
5+
import { Literal } from "obsidian-dataview";
6+
import { DataviewService } from "services/DataviewService";
7+
8+
const dbfolderColumnSortingFn: (
9+
ddbbConfig: LocalSettings
10+
) => SortingFn<RowDataType> =
11+
(ddbbConfig: LocalSettings) =>
12+
(
13+
rowA: Row<RowDataType>,
14+
rowB: Row<RowDataType>,
15+
columnId: string
16+
): number => {
17+
const a = DataviewService.parseLiteral(
18+
rowA.getValue<Literal>(columnId),
19+
InputType.MARKDOWN,
20+
ddbbConfig,
21+
true
22+
)
23+
.toString()
24+
.toLowerCase();
25+
const b = DataviewService.parseLiteral(
26+
rowB.getValue<Literal>(columnId),
27+
InputType.MARKDOWN,
28+
ddbbConfig,
29+
true
30+
)
31+
.toString()
32+
.toLowerCase();
33+
return a === b ? 0 : a > b ? 1 : -1;
34+
};
35+
36+
export default dbfolderColumnSortingFn;

0 commit comments

Comments
 (0)