Skip to content

Commit 6a3449a

Browse files
committed
fix: merge all rows in one tbody
1 parent eaa7d4f commit 6a3449a

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/components/PaginatedTable/TableChunk.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,5 @@ export const TableChunk = typedMemo(function TableChunk<T, F>({
147147
));
148148
};
149149

150-
return (
151-
<tbody
152-
id={id.toString()}
153-
style={{
154-
height: `${dataLength * rowHeight}px`,
155-
display: 'table-row-group',
156-
}}
157-
>
158-
{renderContent()}
159-
</tbody>
160-
);
150+
return <React.Fragment>{renderContent()}</React.Fragment>;
161151
});

src/components/PaginatedTable/useVirtualizedTbodies.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ export const useVirtualizedTbodies = <T, F>({
7171
);
7272
}
7373

74-
// Collect and push active chunks
74+
// Collect active chunks and calculate total height
75+
const activeChunkElements: React.ReactElement[] = [];
76+
let totalActiveHeight = 0;
77+
7578
for (let i = startEmptyCount; i < activeChunks.length && activeChunks[i]; i++) {
76-
chunks.push(
79+
const chunkRowCount = i === activeChunks.length - 1 ? lastChunkSize : chunkSize;
80+
totalActiveHeight += chunkRowCount * rowHeight;
81+
82+
activeChunkElements.push(
7783
<TableChunk<T, F>
7884
key={i}
7985
id={i}
80-
calculatedCount={i === activeChunks.length - 1 ? lastChunkSize : chunkSize}
86+
calculatedCount={chunkRowCount}
8187
chunkSize={chunkSize}
8288
rowHeight={rowHeight}
8389
columns={columns}
@@ -95,6 +101,21 @@ export const useVirtualizedTbodies = <T, F>({
95101
startEmptyCount = i + 1;
96102
}
97103

104+
// Wrap active chunks in a single tbody with calculated height
105+
if (activeChunkElements.length > 0) {
106+
chunks.push(
107+
<tbody
108+
key="active-chunks"
109+
style={{
110+
height: `${totalActiveHeight}px`,
111+
display: 'table-row-group',
112+
}}
113+
>
114+
{activeChunkElements}
115+
</tbody>,
116+
);
117+
}
118+
98119
// Count empty end chunks
99120
const endEmptyCount = activeChunks.length - startEmptyCount;
100121

0 commit comments

Comments
 (0)