22import { Row , flexRender } from "@tanstack/react-table" ;
33import { CSSProperties } from "react" ;
44import { CSS } from "@dnd-kit/utilities" ;
5+ import { FilterModel } from "../types/TableState" ;
6+ import { ReactDataTableProps } from "./ReactDataTableProps" ;
57
6- interface TableRowProps < TData > {
8+ interface TableRowProps < TData , TFilter extends FilterModel = Record < string , never > >
9+ extends Pick < ReactDataTableProps < TData , TFilter > , "onRowClick" | "enableRowClick" > {
710 row : Row < TData > ;
811 enableRowSelection ?: boolean | ( ( row : Row < TData > ) => boolean ) ;
912 fullRowSelectable ?: boolean ;
@@ -12,21 +15,25 @@ interface TableRowProps<TData> {
1215 setNodeRef ?: ( node : HTMLElement | null ) => void ;
1316}
1417
15- const InternalTableRow = < TData , > ( props : TableRowProps < TData > ) => {
16- const { row, rowStyle, setNodeRef, enableRowSelection = false , fullRowSelectable = true } = props ;
18+ const InternalTableRow = < TData , TFilter extends FilterModel = Record < string , never > > ( props : TableRowProps < TData , TFilter > ) => {
19+ const { row, rowStyle, setNodeRef, enableRowSelection = false , fullRowSelectable = true , onRowClick , enableRowClick } = props ;
1720 const isRowSelectionEnabled =
1821 ( typeof enableRowSelection === "function" ? enableRowSelection ( row ) : enableRowSelection ) && fullRowSelectable ;
19-
22+ const isRowClickable = typeof enableRowClick === "function" ? enableRowClick ( row ) : enableRowClick ;
2023 return (
2124 < tr
2225 key = { row . id }
2326 ref = { setNodeRef }
24- onClick = { ( ) => {
27+ onClick = { async ( ) => {
2528 if ( isRowSelectionEnabled ) {
2629 row . toggleSelected ( ) ;
30+ } else if ( isRowClickable && onRowClick ) {
31+ await onRowClick ( row ) ;
32+ } else {
33+ // Nothing to execute
2734 }
2835 } }
29- className = { isRowSelectionEnabled ? "cursor-pointer" : undefined }
36+ className = { isRowSelectionEnabled || isRowClickable ? "cursor-pointer" : undefined }
3037 style = { rowStyle }
3138 >
3239 { row . getVisibleCells ( ) . map ( ( cell ) => (
@@ -38,8 +45,8 @@ const InternalTableRow = <TData,>(props: TableRowProps<TData>) => {
3845 ) ;
3946} ;
4047
41- const DraggableRow = < TData , > ( props : TableRowProps < TData > ) => {
42- const { row, rowStyle, enableRowSelection , fullRowSelectable , enableExpanding } = props ;
48+ const DraggableRow = < TData , TFilter extends FilterModel = Record < string , never > > ( props : TableRowProps < TData , TFilter > ) => {
49+ const { row, rowStyle } = props ;
4350 const { transform, transition, setNodeRef, isDragging } = useSortable ( { id : row . id } ) ;
4451 const draggableStyle : CSSProperties = {
4552 transform : CSS . Transform . toString ( transform ) ,
@@ -49,11 +56,8 @@ const DraggableRow = <TData,>(props: TableRowProps<TData>) => {
4956 position : "relative" ,
5057 } ;
5158 return (
52- < InternalTableRow
53- row = { row }
54- enableRowSelection = { enableRowSelection }
55- enableExpanding = { enableExpanding }
56- fullRowSelectable = { fullRowSelectable }
59+ < InternalTableRow < TData , TFilter >
60+ { ...props }
5761 setNodeRef = { setNodeRef }
5862 rowStyle = { rowStyle ? { ...rowStyle , ...draggableStyle } : draggableStyle }
5963 />
0 commit comments