Skip to content

Commit 402a220

Browse files
Scott DoverScott Dover
authored andcommitted
chore: scroll to top on sort
Signed-off-by: Scott Dover <[email protected]>
1 parent f761116 commit 402a220

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

client/src/webview/ColumnHeader.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
43
import { useRef } from "react";
54

6-
import { AgColumn, GridApi } from "ag-grid-community";
5+
import { AgColumn, ColumnState, GridApi } from "ag-grid-community";
76

87
import { ColumnHeaderProps } from "./ColumnHeaderMenu";
98

@@ -50,6 +49,11 @@ const ColumnHeader = ({
5049
? `${column.sortIndex + 1}`
5150
: "";
5251

52+
const applyColumnState = (state: ColumnState[]) => {
53+
api.applyColumnState({ state, defaultState: { sort: null } });
54+
api.ensureIndexVisible(0);
55+
};
56+
5357
const displayColumnMenu = () => {
5458
if (currentColumn) {
5559
return setColumnMenu(undefined);
@@ -75,29 +79,25 @@ const ColumnHeader = ({
7579
} else {
7680
newColumnState[colIndex].sort = direction;
7781
}
78-
api.applyColumnState({
79-
state: newColumnState,
80-
defaultState: { sort: null },
81-
});
82+
applyColumnState(newColumnState);
8283
},
8384
removeAllSorting: () =>
84-
api.applyColumnState({
85-
state: api
85+
applyColumnState(
86+
api
8687
.getColumnState()
8788
.filter((c) => c.sort)
8889
.map((c) => ({ colId: c.colId, sort: null })),
89-
defaultState: { sort: null },
90-
}),
90+
),
9191
removeFromSort: () =>
92-
api.applyColumnState({
93-
state: api
92+
applyColumnState(
93+
api
9494
.getColumnState()
9595
.sort((a, b) => a.sortIndex - b.sortIndex)
9696
.filter((c) => c.sort && c.colId !== column.colId)
9797
// After we remove the column, lets reindex what's left
9898
.map((c, sortIndex) => ({ ...c, sortIndex })),
99-
defaultState: { sort: null },
100-
}),
99+
),
100+
101101
dismissMenu: () => setColumnMenu(undefined),
102102
});
103103
};

0 commit comments

Comments
 (0)