add download
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
type Table,
|
||||
type VisibilityState
|
||||
} from '@tanstack/react-table'
|
||||
import { createContext, useState, type ReactNode } from 'react'
|
||||
import { createContext, useEffect, useState, type ReactNode } from 'react'
|
||||
import { useSearchParams } from 'react-router'
|
||||
|
||||
import { Card, CardContent } from '@repo/ui/components/ui/card'
|
||||
@@ -28,6 +28,7 @@ interface DataTableProps<TData, TValue> {
|
||||
children?: ReactNode
|
||||
columns: ColumnDef<TData, TValue>[]
|
||||
data: TData[]
|
||||
onRowSelectionChange?: (rowSelection: TData[]) => void
|
||||
pageIndex: number
|
||||
sort: SortingState
|
||||
pageSize: number
|
||||
@@ -45,6 +46,7 @@ export function DataTable<TData, TValue>({
|
||||
pageIndex,
|
||||
pageSize,
|
||||
rowCount,
|
||||
onRowSelectionChange,
|
||||
hiddenColumn = []
|
||||
}: DataTableProps<TData, TValue>) {
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
@@ -88,8 +90,6 @@ export function DataTable<TData, TValue>({
|
||||
})
|
||||
}
|
||||
|
||||
// table.getSelectedRowModel().flatRows.map((row) => row.original)
|
||||
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
@@ -114,6 +114,11 @@ export function DataTable<TData, TValue>({
|
||||
onPaginationChange: setPagination
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const selected = table.getSelectedRowModel().flatRows.map((r) => r.original)
|
||||
onRowSelectionChange?.(selected)
|
||||
}, [rowSelection, table])
|
||||
|
||||
return (
|
||||
<TableContext value={{ table }}>
|
||||
<div className="space-y-2.5 max-md:mb-2">
|
||||
|
||||
Reference in New Issue
Block a user