@@ -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,7 +773,7 @@ export function DataTable<T extends Record<string, unknown>>({
753773 ) }
754774 </ th >
755775 ) ) }
756- { tableConfig . enableColumnResizing && < th aria-hidden = "true" /> }
776+ { renderResizePlaceholderCell ( "th" ) }
757777 </ tr >
758778 ) ) }
759779 </ thead >
@@ -781,7 +801,7 @@ export function DataTable<T extends Record<string, unknown>>({
781801 < div className = "h-6 w-full animate-pulse rounded bg-muted" />
782802 </ td >
783803 ) ) }
784- { tableConfig . enableColumnResizing && < td aria-hidden = "true" /> }
804+ { renderResizePlaceholderCell ( "td" ) }
785805 </ tr >
786806 ) )
787807 ) : table . getRowModel ( ) . rows ?. length ? (
@@ -827,11 +847,14 @@ export function DataTable<T extends Record<string, unknown>>({
827847 ) }
828848 </ td >
829849 ) ) }
830- { tableConfig . enableColumnResizing && < td aria-hidden = "true" /> }
850+ { renderResizePlaceholderCell ( "td" ) }
831851 </ tr >
832852 { row . getIsExpanded ( ) && renderSubRow && (
833853 < tr key = { `expanded-${ row . id } ` } className = "bg-muted/30 hover:bg-muted/30 border-b" >
834- < td colSpan = { row . getVisibleCells ( ) . length + ( tableConfig . enableColumnResizing ? 1 : 0 ) } className = "p-0" >
854+ < td
855+ colSpan = { getVisibleColumnCount ( row . getVisibleCells ( ) . length ) }
856+ className = "p-0"
857+ >
835858 { renderSubRow ( { row : row . original , table : tableContextRef . current } ) }
836859 </ td >
837860 </ tr >
@@ -842,7 +865,7 @@ export function DataTable<T extends Record<string, unknown>>({
842865 < tr data-slot = "table-row" >
843866 < td
844867 data-slot = "table-cell"
845- colSpan = { resolvedColumns . length + ( tableConfig . enableColumnResizing ? 1 : 0 ) }
868+ colSpan = { totalVisibleColumns }
846869 className = "h-24 text-center text-muted-foreground"
847870 >
848871 No results.
0 commit comments