Skip to content

Commit 9be551c

Browse files
committed
Make sure useColumnSort can be traced back if need be
1 parent 08e7e69 commit 9be551c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/source/src/use-column-sort.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ type Props = Pick<DataEditorProps, "getCellContent" | "rows" | "columns"> & {
3939
direction?: "asc" | "desc";
4040
};
4141
};
42-
type Result = Pick<DataEditorProps, "getCellContent">;
42+
type Result = Pick<DataEditorProps, "getCellContent"> & {
43+
getOriginalIndex: (index: number) => number;
44+
};
4345

4446
export function useColumnSort(p: Props): Result {
4547
const { sort, rows, getCellContent: getCellContentIn } = p;
@@ -73,6 +75,14 @@ export function useColumnSort(p: Props): Result {
7375
return result;
7476
}, [getCellContentIn, rows, sort?.mode, dir, sortCol]);
7577

78+
const getOriginalIndex = React.useCallback(
79+
(index: number): number => {
80+
if (sortMap === undefined) return index;
81+
return sortMap[index];
82+
},
83+
[sortMap]
84+
);
85+
7686
const getCellContent = React.useCallback<typeof getCellContentIn>(
7787
([col, row]) => {
7888
if (sortMap === undefined) return getCellContentIn([col, row]);
@@ -83,10 +93,11 @@ export function useColumnSort(p: Props): Result {
8393
);
8494

8595
if (sortMap === undefined) {
86-
return { getCellContent: p.getCellContent };
96+
return { getCellContent: p.getCellContent, getOriginalIndex };
8797
}
8898

8999
return {
100+
getOriginalIndex,
90101
getCellContent,
91102
};
92103
}

packages/source/src/use-movable-columns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DataEditorProps, GridColumn } from "@glideapps/glide-data-grid";
33
import orderBy from "lodash/orderBy";
44

55
function colToKey(c: GridColumn) {
6-
return `${c.group ?? ""}/${c.title}`;
6+
return c.id ?? `${c.group ?? ""}/${c.title}`;
77
}
88

99
function looseCompareCol(a: GridColumn, b: GridColumn | string): boolean {

0 commit comments

Comments
 (0)