@@ -670,6 +670,26 @@ export function DataTable<T extends Record<string, unknown>>({
670670 pageSizeOptionsProp ??
671671 tableConfig . pageSizeOptions ?? [ 10 , 20 , 30 , 40 , 50 ] ;
672672
673+ const resizePlaceholderColumnCount = tableConfig . enableColumnResizing ? 1 : 0 ;
674+
675+ const getVisibleColumnCount = ( columnCount : number ) =>
676+ columnCount + resizePlaceholderColumnCount ;
677+
678+ const renderResizePlaceholderCell = ( cellTag : "th" | "td" ) => {
679+ if ( ! resizePlaceholderColumnCount ) {
680+ return null ;
681+ }
682+
683+ return React . createElement ( cellTag , {
684+ "aria-hidden" : true ,
685+ role : "presentation" ,
686+ } ) ;
687+ } ;
688+
689+ const totalVisibleColumns = getVisibleColumnCount (
690+ table . getVisibleLeafColumns ( ) . length
691+ ) ;
692+
673693 return (
674694 < div className = { cn ( "space-y-4" , className ) } >
675695 { tableConfig . enableToolbar && (
@@ -753,6 +773,7 @@ export function DataTable<T extends Record<string, unknown>>({
753773 ) }
754774 </ th >
755775 ) ) }
776+ { renderResizePlaceholderCell ( "th" ) }
756777 </ tr >
757778 ) ) }
758779 </ thead >
@@ -780,6 +801,7 @@ export function DataTable<T extends Record<string, unknown>>({
780801 < div className = "h-6 w-full animate-pulse rounded bg-muted" />
781802 </ td >
782803 ) ) }
804+ { renderResizePlaceholderCell ( "td" ) }
783805 </ tr >
784806 ) )
785807 ) : table . getRowModel ( ) . rows ?. length ? (
@@ -825,10 +847,14 @@ export function DataTable<T extends Record<string, unknown>>({
825847 ) }
826848 </ td >
827849 ) ) }
850+ { renderResizePlaceholderCell ( "td" ) }
828851 </ tr >
829852 { row . getIsExpanded ( ) && renderSubRow && (
830853 < tr key = { `expanded-${ row . id } ` } className = "bg-muted/30 hover:bg-muted/30 border-b" >
831- < td colSpan = { row . getVisibleCells ( ) . length } className = "p-0" >
854+ < td
855+ colSpan = { getVisibleColumnCount ( row . getVisibleCells ( ) . length ) }
856+ className = "p-0"
857+ >
832858 { renderSubRow ( { row : row . original , table : tableContextRef . current } ) }
833859 </ td >
834860 </ tr >
@@ -839,7 +865,7 @@ export function DataTable<T extends Record<string, unknown>>({
839865 < tr data-slot = "table-row" >
840866 < td
841867 data-slot = "table-cell"
842- colSpan = { resolvedColumns . length }
868+ colSpan = { totalVisibleColumns }
843869 className = "h-24 text-center text-muted-foreground"
844870 >
845871 No results.
0 commit comments