import { DropdownMenuTrigger } from '@radix-ui/react-dropdown-menu' import { type Column, type Table } from '@tanstack/react-table' import { Settings2 } from 'lucide-react' import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, } from '@/components/ui/dropdown-menu' type DataTableViewOptionsProps = { table: Table } const getColumnLabel = (column: Column) => { const metaLabel = column.columnDef.meta?.label const header = column.columnDef.header if (typeof metaLabel === 'string') { return metaLabel } if (typeof header === 'string') { return header } return column.id } export function DataTableViewOptions({ table }: DataTableViewOptionsProps) { return ( 显示列 {table .getAllColumns() .filter((column) => typeof column.accessorFn !== 'undefined' && column.getCanHide()) .map((column) => { return ( column.toggleVisibility(!!value)} > {getColumnLabel(column)} ) })} ) }