update
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
'use client'
|
||||
|
||||
import { useContext } from 'react'
|
||||
|
||||
import { type Table } from '@tanstack/react-table'
|
||||
import { Columns2Icon } from 'lucide-react'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
@@ -13,20 +10,14 @@ import {
|
||||
DropdownMenuTrigger
|
||||
} from '@repo/ui/components/ui/dropdown-menu'
|
||||
import { cn } from '@repo/ui/lib/utils'
|
||||
import { TableContext } from './data-table'
|
||||
import { useDataTable } from './data-table'
|
||||
|
||||
export function DataTableViewOptions<TData>({
|
||||
className
|
||||
}: {
|
||||
className: string
|
||||
}) {
|
||||
const ctx = useContext(TableContext) as { table: Table<TData> } | null
|
||||
|
||||
if (!ctx) {
|
||||
throw new Error('TableContext is null')
|
||||
}
|
||||
|
||||
const { table } = ctx
|
||||
const { table } = useDataTable()
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
@@ -43,13 +34,16 @@ export function DataTableViewOptions<TData>({
|
||||
typeof column.accessorFn !== 'undefined' && column.getCanHide()
|
||||
)
|
||||
.map((column) => {
|
||||
// @ts-ignore
|
||||
const title = column.columnDef?.meta?.title ?? column.id
|
||||
|
||||
return (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={column.id}
|
||||
checked={column.getIsVisible()}
|
||||
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
||||
>
|
||||
{column.columnDef?.meta?.title ?? column.id}
|
||||
{title}
|
||||
</DropdownMenuCheckboxItem>
|
||||
)
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user