Skip to content

Commit 6726820

Browse files
committed
fix: remove spacers - use absolute positioning
1 parent 8922143 commit 6726820

File tree

2 files changed

+16
-52
lines changed

2 files changed

+16
-52
lines changed

src/components/PaginatedTable/PaginatedTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export const PaginatedTable = <T, F>({
131131
const renderTable = () => (
132132
<table className={b('table')}>
133133
<TableHead columns={columns} onSort={setSortParams} onColumnsResize={onColumnsResize} />
134-
{renderChunks()}
134+
<div className={b('table-body')} style={{height: totalItems * rowHeight}}>
135+
{renderChunks()}
136+
</div>
135137
</table>
136138
);
137139

src/components/PaginatedTable/useVirtualizedTbodies.tsx

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,12 @@ export const useVirtualizedTbodies = <T, F>({
4848
const endRow = visibleRowRange.end;
4949

5050
const renderChunks = React.useCallback(() => {
51-
const chunks: React.ReactElement[] = [];
52-
5351
// Calculate which chunks contain visible rows
5452
const totalChunks = Math.ceil(totalItems / chunkSize);
5553
const startChunk = Math.max(0, Math.floor(startRow / chunkSize));
5654
const endChunk = Math.min(totalChunks - 1, Math.floor(endRow / chunkSize));
5755

58-
// Push start spacer for rows before visible range
59-
const startSpacerHeight = startRow * rowHeight;
60-
if (startSpacerHeight > 0) {
61-
chunks.push(
62-
<tbody
63-
key="spacer-start"
64-
style={{
65-
height: `${startSpacerHeight}px`,
66-
display: 'block',
67-
}}
68-
/>,
69-
);
70-
}
71-
72-
// Collect active chunks and calculate height for visible rows only
56+
// Collect active chunks
7357
const activeChunkElements: React.ReactElement[] = [];
7458

7559
for (let i = startChunk; i <= endChunk; i++) {
@@ -98,41 +82,19 @@ export const useVirtualizedTbodies = <T, F>({
9882
);
9983
}
10084

101-
// Wrap active chunks in a single tbody
102-
if (activeChunkElements.length > 0) {
103-
// Calculate height based on visible rows only
104-
const visibleRowCount = endRow - startRow + 1;
105-
const totalActiveHeight = visibleRowCount * rowHeight;
106-
107-
chunks.push(
108-
<tbody
109-
key="active-chunks"
110-
style={{
111-
height: `${totalActiveHeight}px`,
112-
display: 'table-row-group',
113-
}}
114-
>
115-
{activeChunkElements}
116-
</tbody>,
117-
);
118-
}
119-
120-
// Add end spacer for rows after visible range
121-
const endSpacerHeight = Math.max(0, (totalItems - startRow - 1) * rowHeight);
122-
123-
if (endSpacerHeight > 0) {
124-
chunks.push(
125-
<tbody
126-
key="spacer-end"
127-
style={{
128-
height: `${endSpacerHeight}px`,
129-
display: 'block',
130-
}}
131-
/>,
132-
);
133-
}
85+
const activeChunksTopOffset = startRow * rowHeight;
13486

135-
return chunks;
87+
return (
88+
<tbody
89+
style={{
90+
position: 'absolute',
91+
transform: `translateY(${activeChunksTopOffset}px)`,
92+
willChange: 'transform',
93+
}}
94+
>
95+
{activeChunkElements}
96+
</tbody>
97+
);
13698
}, [
13799
startRow,
138100
endRow,

0 commit comments

Comments
 (0)