Skip to content

Commit

Permalink
fix(table): fixes isSorted prop
Browse files Browse the repository at this point in the history
438
  • Loading branch information
xavierdonnellon committed Jun 27, 2023
1 parent 24a697a commit 74f09ba
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,23 +399,8 @@ const Table = ({
return;
}

let copiedData: RowEntry[] = [];

// Make shallow copy if references are equal
if (sortedData === data) {
console.log('Copying data for sorting');
copiedData = [...data];

// Shallow copy each group, if this is grouped data
if (copiedData.length > 0 && Array.isArray(copiedData[0])) {
for (let groupIndex = 0; groupIndex < copiedData.length; groupIndex++) {
copiedData[groupIndex] = [...(copiedData[groupIndex] as RowEntry[])];
}
}
} else {
// re-use existing copy
copiedData = sortedData;
}
// Shallow copy the data to keep `data` prop un-mutated.
const copiedData = [...data];

// If the first element of the data is not an array, then we do not have groups
if (!Array.isArray(copiedData[0])) {
Expand All @@ -424,6 +409,11 @@ const Table = ({
compareEntries(row1[key], row2[key], copiedColumns[key], newDirection),
);
} else {
// Shallow copy each group
for (let groupIndex = 0; groupIndex < copiedData.length; groupIndex++) {
copiedData[groupIndex] = [...(copiedData[groupIndex] as RowEntry[])];
}

// Sort the content of each group
(copiedData as Array<Array<RowEntry>>).forEach(group => {
group.sort((row1: any, row2: any) =>
Expand Down

0 comments on commit 74f09ba

Please sign in to comment.