@@ -77,7 +77,11 @@ export function walkColumns(
7777 let x = 0 ;
7878 let clipX = 0 ; // this tracks the total width of sticky cols
7979 const drawY = totalHeaderHeight + translateY ;
80- const clipXRight = freezeTrailingColumns === 0 ? 0 : effectiveCols . slice ( - freezeTrailingColumns ) . reduce ( ( acc , col ) => acc + col . width , 0 ) ;
80+
81+ let clipXRight = 0 ;
82+ for ( let i = effectiveCols . length - freezeTrailingColumns ; i < effectiveCols . length ; i ++ ) {
83+ clipXRight += effectiveCols [ i ] . width ;
84+ }
8185
8286 for ( let i = 0 ; i < effectiveCols . length - freezeTrailingColumns ; i ++ ) {
8387 const c = effectiveCols [ i ] ;
@@ -121,9 +125,12 @@ export function walkGroups(
121125 let x = 0 ;
122126 let clipX = 0 ;
123127
124- const effectiveColsRight = freezeTrailingColumns === 0 ? [ ] : effectiveCols . slice ( - freezeTrailingColumns ) ;
125- const widthRight = effectiveColsRight . reduce ( ( acc , col ) => acc + col . width , 0 ) ;
126- width -= widthRight ;
128+ // Pre-calculate right freeze columns total width
129+ let widthRight = 0 ;
130+ for ( let i = effectiveCols . length - freezeTrailingColumns ; i < effectiveCols . length ; i ++ ) {
131+ widthRight += effectiveCols [ i ] . width ;
132+ }
133+ const clippedWidth = width - widthRight ;
127134
128135 for ( let index = 0 ; index < effectiveCols . length - freezeTrailingColumns ; index ++ ) {
129136 const startCol = effectiveCols [ index ] ;
@@ -150,7 +157,7 @@ export function walkGroups(
150157 const t = startCol . sticky ? 0 : translateX ;
151158 const localX = x + t ;
152159 const delta = startCol . sticky ? 0 : Math . max ( 0 , clipX - localX ) ;
153- const w = Math . min ( boxWidth - delta , width - ( localX + delta ) ) ;
160+ const w = Math . min ( boxWidth - delta , clippedWidth - ( localX + delta ) ) ;
154161 cb (
155162 [ startCol . sourceIndex , effectiveCols [ end - 1 ] . sourceIndex ] ,
156163 startCol . group ?? "" ,
@@ -163,18 +170,21 @@ export function walkGroups(
163170 x += boxWidth ;
164171 }
165172
166- for ( let index = 0 ; index < effectiveColsRight . length ; index ++ ) {
167- const startCol = effectiveColsRight [ index ] ;
173+ let currentWidth = clippedWidth ;
174+ const rightStartIndex = effectiveCols . length - freezeTrailingColumns ;
175+
176+ for ( let index = rightStartIndex ; index < effectiveCols . length ; index ++ ) {
177+ const startCol = effectiveCols [ index ] ;
168178
169179 let end = index + 1 ;
170180 let boxWidth = startCol . width ;
171181
172182 while (
173- end < effectiveColsRight . length &&
174- isGroupEqual ( effectiveColsRight [ end ] . group , startCol . group ) &&
175- effectiveColsRight [ end ] . sticky === effectiveColsRight [ index ] . sticky
183+ end < effectiveCols . length &&
184+ isGroupEqual ( effectiveCols [ end ] . group , startCol . group ) &&
185+ effectiveCols [ end ] . sticky === effectiveCols [ index ] . sticky
176186 ) {
177- const endCol = effectiveColsRight [ end ] ;
187+ const endCol = effectiveCols [ end ] ;
178188 boxWidth += endCol . width ;
179189 end ++ ;
180190 index ++ ;
@@ -183,20 +193,20 @@ export function walkGroups(
183193 }
184194 }
185195
186- const t = width + boxWidth ;
196+ const t = currentWidth + boxWidth ;
187197 const localX = t - boxWidth ;
188198 const delta = 0 ;
189199 const w = boxWidth - delta ;
190200 cb (
191- [ startCol . sourceIndex , effectiveColsRight [ end - 1 ] . sourceIndex ] ,
201+ [ startCol . sourceIndex , effectiveCols [ end - 1 ] . sourceIndex ] ,
192202 startCol . group ?? "" ,
193203 localX + delta ,
194204 0 ,
195205 w ,
196206 groupHeaderHeight
197207 ) ;
198208
199- width += w ;
209+ currentWidth += w ;
200210 }
201211}
202212
0 commit comments