@@ -33,14 +33,14 @@ export function DataTable<TData>({
3333 if ( onRowClick ) {
3434 onRowClick ( row ) ;
3535 }
36- if ( getRowId ) {
36+ if ( getRowId && rowClickBasePath ) {
3737 const id = getRowId ( row ) ;
3838 router . push ( `${ rowClickBasePath } /${ id } ` ) ;
3939 }
4040 } ;
4141
42- // Apply client-side filtering
4342 const filteredRows = table . getFilteredRowModel ( ) . rows ;
43+ const isRowClickable = ! ! ( getRowId && rowClickBasePath ) || ! ! onRowClick ;
4444
4545 return (
4646 < div className = { cn ( 'space-y-4' , className ) } { ...props } >
@@ -78,25 +78,27 @@ export function DataTable<TData>({
7878 < TableRow
7979 key = { row . id }
8080 data-state = { row . getIsSelected ( ) && 'selected' }
81- className = { cn ( ( getRowId || onRowClick ) && 'hover:bg-muted/50 cursor-pointer' ) }
82- onClick = { ( ) => handleRowClick ( row . original ) }
81+ className = { cn ( isRowClickable && 'hover:bg-muted/50 cursor-pointer' ) }
82+ onClick = { isRowClickable ? ( ) => handleRowClick ( row . original ) : undefined }
8383 >
84- { row . getVisibleCells ( ) . map ( ( cell , index ) => (
85- < TableCell
86- key = { cell . id }
87- className = { cn (
88- index !== 0 && 'hidden md:table-cell' ,
89- index === 0 && 'truncate' ,
90- ) }
91- style = { {
92- ...getCommonPinningStyles ( {
93- column : cell . column ,
94- } ) ,
95- } }
96- >
97- { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
98- </ TableCell >
99- ) ) }
84+ { row . getVisibleCells ( ) . map ( ( cell , index ) => {
85+ return (
86+ < TableCell
87+ key = { cell . id }
88+ className = { cn (
89+ index !== 0 && 'hidden md:table-cell' ,
90+ index === 0 && 'truncate' ,
91+ ) }
92+ style = { {
93+ ...getCommonPinningStyles ( {
94+ column : cell . column ,
95+ } ) ,
96+ } }
97+ >
98+ { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
99+ </ TableCell >
100+ ) ;
101+ } ) }
100102 </ TableRow >
101103 ) )
102104 ) : (
0 commit comments