From 70ef0d74f350e2cba5d11489876d5e489a608a66 Mon Sep 17 00:00:00 2001 From: mayorbyrne Date: Wed, 5 Jul 2023 23:15:14 -0500 Subject: [PATCH] feat: add ability to initially sort a column descending --- src/view/plugin/sort/sort.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/view/plugin/sort/sort.tsx b/src/view/plugin/sort/sort.tsx index 5b19779c..3e9b6f63 100644 --- a/src/view/plugin/sort/sort.tsx +++ b/src/view/plugin/sort/sort.tsx @@ -15,6 +15,8 @@ import { useStore } from '../../../hooks/useStore'; // column specific config export interface SortConfig { compare?: Comparator; + // 1 ascending, -1 descending + direction?: 1 | -1; } // generic sort config: @@ -69,6 +71,11 @@ export function Sort( if (!currentColumn) { setDirection(0); } else { + // if the direction is not set, initialize the selected + // column direction with the passed prop (default to ascending) + if (direction === 0) { + currentColumn.direction = props.direction ?? 1; + } setDirection(currentColumn.direction); } }, [state]);