File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -255,12 +255,19 @@ export function useLayout<R extends GridRowModel>(params: UseLayoutParams<R>): L
255255 return rowHeight + getDetailPanelLayoutHeight ( panelHeight , detailPanelHeights ?. get ( id ) ) ;
256256 } ;
257257
258- const rowHeights = unpinnedRows . map ( ( row , index ) => heightOf ( row , pinnedTopRowsLength + index ) ) ;
259-
260- const cumulativeHeights = rowHeights . reduce ( ( acc , height , index ) => {
261- acc . push ( ( acc [ index - 1 ] || 0 ) + height ) ;
262- return acc ;
263- } , [ ] as number [ ] ) ;
258+ // One pass with preallocated arrays: this runs for every row after each sort or filter. With
259+ // no detail panel open every row has the plain height, so row ids are not looked up.
260+ const rowCount = unpinnedRows . length ;
261+ const rowHeights = new Array < number > ( rowCount ) ;
262+ const cumulativeHeights = new Array < number > ( rowCount ) ;
263+ const anyPanelOpen = expandedRowIds . size > 0 ;
264+ let runningHeight = 0 ;
265+ for ( let index = 0 ; index < rowCount ; index ++ ) {
266+ const height = anyPanelOpen ? heightOf ( unpinnedRows [ index ] , pinnedTopRowsLength + index ) : rowHeight ;
267+ rowHeights [ index ] = height ;
268+ runningHeight = ( runningHeight || 0 ) + height ; // as before: a NaN total restarts from 0
269+ cumulativeHeights [ index ] = runningHeight ;
270+ }
264271
265272 const skeletonCount = ( paginationMode === 'infinite' && isLoading && unpinnedRows . length > 0 )
266273 ? Math . min ( pageSize , 20 )
You can’t perform that action at this time.
0 commit comments