@@ -750,27 +750,43 @@ export function Table({
750750 const colIndex = cols . findIndex ( ( c ) => c . name === columnName )
751751 if ( colIndex === - 1 ) return
752752
753+ const column = cols [ colIndex ]
754+ if ( column . type === 'boolean' ) return
755+
756+ const host = containerRef . current ?? document . body
753757 const currentRows = rowsRef . current
754758 let maxWidth = COL_WIDTH_MIN
755759
756760 const measure = document . createElement ( 'span' )
757- measure . style . cssText = 'position:absolute;visibility:hidden;white-space:nowrap'
758- document . body . appendChild ( measure )
761+ measure . style . cssText = 'position:absolute;visibility:hidden;white-space:nowrap;top:-9999px '
762+ host . appendChild ( measure )
759763
760764 try {
761765 measure . className = 'font-medium text-small'
762766 measure . textContent = columnName
763- maxWidth = Math . max ( maxWidth , measure . offsetWidth + 57 )
767+ maxWidth = Math . max ( maxWidth , measure . getBoundingClientRect ( ) . width + 57 )
764768
765769 measure . className = 'text-small'
766770 for ( const row of currentRows ) {
767771 const val = row . data [ columnName ]
768772 if ( val == null ) continue
769- measure . textContent = String ( val )
770- maxWidth = Math . max ( maxWidth , measure . offsetWidth + 17 )
773+ let text : string
774+ if ( column . type === 'json' ) {
775+ try {
776+ text = JSON . stringify ( val )
777+ } catch {
778+ text = String ( val )
779+ }
780+ } else if ( column . type === 'date' ) {
781+ text = storageToDisplay ( String ( val ) )
782+ } else {
783+ text = String ( val )
784+ }
785+ measure . textContent = text
786+ maxWidth = Math . max ( maxWidth , measure . getBoundingClientRect ( ) . width + 17 )
771787 }
772788 } finally {
773- document . body . removeChild ( measure )
789+ host . removeChild ( measure )
774790 }
775791
776792 const newWidth = Math . min ( Math . ceil ( maxWidth ) , 600 )
0 commit comments