From f515f6238e9882d153b5a83b2217560ac4ce9b26 Mon Sep 17 00:00:00 2001 From: Jacob Wallraff Date: Wed, 8 Nov 2023 14:12:19 -0800 Subject: [PATCH 1/2] Move header creation before sort order determination --- src/DataTable/useTable.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DataTable/useTable.ts b/src/DataTable/useTable.ts index c9a6b874cc1..5d4a5ec2c62 100644 --- a/src/DataTable/useTable.ts +++ b/src/DataTable/useTable.ts @@ -71,15 +71,6 @@ export function useTable({ } } - // Update the row order and apply the current sort column to the incoming data - if (data !== prevData) { - setPrevData(data) - setRowOrder(data) - if (sortByColumn) { - sortRows(sortByColumn) - } - } - const headers = columns.map(column => { const id = column.id ?? column.field if (id === undefined) { @@ -102,6 +93,15 @@ export function useTable({ } }) + // Update the row order and apply the current sort column to the incoming data + if (data !== prevData) { + setPrevData(data) + setRowOrder(data) + if (sortByColumn) { + sortRows(sortByColumn) + } + } + /** * Sort the input row data by the given header */ From ed6f176f7997ab0b25c2daa8cb5d9525b7748640 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 9 Nov 2023 10:08:32 -0600 Subject: [PATCH 2/2] Create slimy-foxes-wash.md --- .changeset/slimy-foxes-wash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slimy-foxes-wash.md diff --git a/.changeset/slimy-foxes-wash.md b/.changeset/slimy-foxes-wash.md new file mode 100644 index 00000000000..1f6da28c4d1 --- /dev/null +++ b/.changeset/slimy-foxes-wash.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +Fix issue in DataTable so that sort order is determined after column headers are created