11import { type Table as TanstackTable , flexRender } from '@tanstack/react-table' ;
2- import { useRouter } from 'next/navigation ' ;
2+ import Link from 'next/link ' ;
33import type * as React from 'react' ;
44
55import { getCommonPinningStyles } from '@/lib/data-table' ;
@@ -10,8 +10,8 @@ import { DataTablePagination } from './data-table-pagination';
1010interface DataTableProps < TData > extends React . ComponentProps < 'div' > {
1111 table : TanstackTable < TData > ;
1212 actionBar ?: React . ReactNode ;
13- getRowId ? : ( row : TData ) => string ;
14- rowClickBasePath ? : string ;
13+ getRowId : ( row : TData ) => string ;
14+ rowClickBasePath : string ;
1515 tableId ?: string ;
1616 onRowClick ?: ( row : TData ) => void ;
1717}
@@ -27,19 +27,12 @@ export function DataTable<TData>({
2727 onRowClick,
2828 ...props
2929} : DataTableProps < TData > ) {
30- const router = useRouter ( ) ;
31-
3230 const handleRowClick = ( row : TData ) => {
3331 if ( onRowClick ) {
3432 onRowClick ( row ) ;
3533 }
36- if ( getRowId ) {
37- const id = getRowId ( row ) ;
38- router . push ( `${ rowClickBasePath } /${ id } ` ) ;
39- }
4034 } ;
4135
42- // Apply client-side filtering
4336 const filteredRows = table . getFilteredRowModel ( ) . rows ;
4437
4538 return (
@@ -74,31 +67,42 @@ export function DataTable<TData>({
7467 </ TableHeader >
7568 < TableBody >
7669 { filteredRows . length ? (
77- filteredRows . map ( ( row ) => (
78- < TableRow
79- key = { row . id }
80- data-state = { row . getIsSelected ( ) && 'selected' }
81- className = { cn ( ( getRowId || onRowClick ) && 'hover:bg-muted/50 cursor-pointer' ) }
82- onClick = { ( ) => handleRowClick ( row . original ) }
83- >
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- ) ) }
100- </ TableRow >
101- ) )
70+ filteredRows . map ( ( row ) => {
71+ const id = getRowId ( row . original ) ;
72+ const href = `${ rowClickBasePath } /${ id } ` ;
73+
74+ return (
75+ < TableRow
76+ key = { row . id }
77+ data-state = { row . getIsSelected ( ) && 'selected' }
78+ className = "hover:bg-muted/50"
79+ >
80+ { row . getVisibleCells ( ) . map ( ( cell , index ) => (
81+ < TableCell
82+ key = { cell . id }
83+ className = { cn (
84+ index !== 0 && 'hidden md:table-cell' ,
85+ index === 0 && 'truncate' ,
86+ ) }
87+ style = { {
88+ ...getCommonPinningStyles ( {
89+ column : cell . column ,
90+ } ) ,
91+ } }
92+ >
93+ < Link
94+ href = { href }
95+ onClick = { ( ) => handleRowClick ( row . original ) }
96+ className = "block w-full h-full"
97+ style = { { textDecoration : 'none' , color : 'inherit' } }
98+ >
99+ { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
100+ </ Link >
101+ </ TableCell >
102+ ) ) }
103+ </ TableRow >
104+ ) ;
105+ } )
102106 ) : (
103107 < TableRow >
104108 < TableCell
0 commit comments