T
TanStack2y ago
useful-bronze

Help with TanStack Table onRowClick

Hey TanStack Community, is there a way I can do <TanStackTable onRowClick={rowData => callSomeFunction(rowData.id, rowData.name)}
3 Replies
useful-bronze
useful-bronzeOP2y ago
<TanStackTable onRowClick={rowData => callSomeFunction(rowData.id, rowData.name)} /> can you elaborate more on to how it helps in my case
initial-rose
initial-rose2y ago
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
className="cursor-pointer"
onClick={() => handleRowClick(row)}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell
colSpan={columns.length}
className="text-center"
>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
className="cursor-pointer"
onClick={() => handleRowClick(row)}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell
colSpan={columns.length}
className="text-center"
>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
- thats how I handle onclick events for rows

Did you find this page helpful?