Skip to content

Commit dd8985e

Browse files
authored
Merge pull request #1366 from mayorbyrne/initial_sort
feat: add ability to initially sort a column descending
2 parents df24682 + 70ef0d7 commit dd8985e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/view/plugin/sort/sort.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { useStore } from '../../../hooks/useStore';
1515
// column specific config
1616
export interface SortConfig {
1717
compare?: Comparator<TCell>;
18+
// 1 ascending, -1 descending
19+
direction?: 1 | -1;
1820
}
1921

2022
// generic sort config:
@@ -96,6 +98,11 @@ export function Sort(
9698
if (!currentColumn) {
9799
setDirection(0);
98100
} else {
101+
// if the direction is not set, initialize the selected
102+
// column direction with the passed prop (default to ascending)
103+
if (direction === 0) {
104+
currentColumn.direction = props.direction ?? 1;
105+
}
99106
setDirection(currentColumn.direction);
100107
}
101108
}, [state]);

0 commit comments

Comments
 (0)