@@ -231,7 +231,7 @@ export function Table<
231
231
232
232
// Determine the id of the last left sticky column (used to draw a visual separator in the UI)
233
233
const lastStickyColumnIndex = flatColumns
234
- . map ( ( c ) => c . accessor )
234
+ . map ( ( c ) => c . id ?? c . accessor )
235
235
. indexOf ( stickyLeftColumnsIds [ stickyLeftColumnsIds . length - 1 ] ) ;
236
236
237
237
// Keep a style object for each sticky column, which will be updated by the useLayoutEffect below
@@ -242,23 +242,24 @@ export function Table<
242
242
// Keep a state for the height of the first row of headers, which will be updated by the useLayoutEffect below
243
243
const [ stickyHeaderHeight , setStickyHeaderHeight ] = useState ( 0 ) ;
244
244
245
+ const tableContainerRef = useRef < HTMLDivElement > ( null ) ;
246
+ const getHeaderById = ( id : string ) =>
247
+ // Search header only inside the table container, to avoid selecting headers from other tables
248
+ tableContainerRef . current ! . querySelector ( `[id='header-cell-${ id } ']` ) ;
249
+
245
250
/** Get the width of each sticky column (using the header width as reference) and use it to set the `left` of each sticky column.
246
251
* Each sticky column must have as `left` the total width of the previous sticky columns.
247
252
*/
248
253
useLayoutEffect ( ( ) => {
249
254
// Make this computation only if we have any data, because headers are not rendered when there are no rows
250
255
// and we need them to get the column width.
251
256
if ( data . length > 0 ) {
252
- const columnWidths = stickyLeftColumnsIds . map (
253
- ( id ) => document . getElementById ( `header-cell-${ id } ` ) ! . clientWidth
254
- ) ;
257
+ const columnWidths = stickyLeftColumnsIds . map ( ( id ) => getHeaderById ( id ) ! . clientWidth ) ;
255
258
const columnGroupWidths = stickyLeftColumnGroupsIds . map (
256
- ( id ) => document . getElementById ( `header-cell- ${ id } ` ) ! . clientWidth
259
+ ( id ) => getHeaderById ( id ) ! . clientWidth
257
260
) ;
258
261
const columnGroupHeight = Math . max (
259
- ...headerGroups [ 0 ] . headers . map ( ( h ) =>
260
- h . columns ? document . getElementById ( `header-cell-${ h . id } ` ) ! . clientHeight : 0
261
- )
262
+ ...headerGroups [ 0 ] . headers . map ( ( h ) => ( h . columns ? getHeaderById ( h . id ) ! . clientHeight : 0 ) )
262
263
) ;
263
264
264
265
const styleReducer =
@@ -304,8 +305,6 @@ export function Table<
304
305
305
306
const flatRows = rows . flatMap ( ( row ) => ( row . isGrouped ? [ row , ...row . leafRows ] : [ row ] ) ) ;
306
307
307
- const tableContainerRef = useRef < HTMLDivElement > ( null ) ;
308
-
309
308
const virtualizeRows =
310
309
typeof virtualizeRowsConfig === "boolean" ? virtualizeRowsConfig : virtualizeRowsConfig != null ;
311
310
const estimateSize =
0 commit comments