@@ -57,7 +57,7 @@ import BodyContext from './context/BodyContext';
57
57
import Body from './Body' ;
58
58
import useColumns from './hooks/useColumns' ;
59
59
import { useFrameState , useTimeoutLock } from './hooks/useFrame' ;
60
- import { getPathValue , mergeObject , validateValue , newArr } from './utils/valueUtil' ;
60
+ import { getPathValue , mergeObject , validateValue , getColumnsKey } from './utils/valueUtil' ;
61
61
import ResizeContext from './context/ResizeContext' ;
62
62
import useStickyOffsets from './hooks/useStickyOffsets' ;
63
63
import ColGroup from './ColGroup' ;
@@ -318,7 +318,11 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
318
318
const scrollBodyRef = React . useRef < HTMLDivElement > ( ) ;
319
319
const [ pingedLeft , setPingedLeft ] = React . useState ( false ) ;
320
320
const [ pingedRight , setPingedRight ] = React . useState ( false ) ;
321
- const [ colWidths , updateColWidths ] = useFrameState < number [ ] > ( newArr ( flattenColumns . length ) ) ;
321
+ const [ colsWidths , updateColsWidths ] = useFrameState ( new Map < React . Key , number > ( ) ) ;
322
+
323
+ // Convert map to number width
324
+ const colsKeys = getColumnsKey ( flattenColumns ) ;
325
+ const colWidths = colsKeys . map ( columnKey => colsWidths . get ( columnKey ) ) ;
322
326
const stickyOffsets = useStickyOffsets ( colWidths , flattenColumns . length ) ;
323
327
324
328
const fixHeader = hasData && scroll && validateValue ( scroll . y ) ;
@@ -342,11 +346,11 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
342
346
} ;
343
347
}
344
348
345
- function onColumnResize ( colIndex : number , width : number ) {
346
- updateColWidths ( ( widths : number [ ] ) => {
347
- const newWidth = widths . slice ( 0 , flattenColumns . length ) ;
348
- newWidth [ colIndex ] = width ;
349
- return newWidth ;
349
+ function onColumnResize ( columnKey : React . Key , width : number ) {
350
+ updateColsWidths ( widths => {
351
+ const newWidths = new Map ( widths ) ;
352
+ newWidths . set ( columnKey , width ) ;
353
+ return newWidths ;
350
354
} ) ;
351
355
}
352
356
0 commit comments