"use client" import * as React from "react" import { type ColumnDef } from "@tanstack/react-table" import { type DataTableRowAction } from "@/types/table" import { formatDate } from "@/lib/utils" import { Checkbox } from "@/components/ui/checkbox" import { Button } from "@/components/ui/button" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" // Material 타입 정의 (서비스에서 반환되는 타입과 일치) type Material = { id: number; MATKL: string | null; // 자재그룹 MATNR: string | null; // 자재코드 ZZNAME: string | null; // 자재명 ZZPJT: string | null; // 프로젝트 createdAt: Date; updatedAt: Date; } interface GetColumnsProps { setRowAction: React.Dispatch | null>> } /** * Material 테이블 컬럼 정의 */ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 1) select 컬럼 (체크박스) // ---------------------------------------------------------------- const selectColumn: ColumnDef = { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), size: 40, enableSorting: false, enableHiding: false, } // ---------------------------------------------------------------- // 2) 데이터 컬럼들 // ---------------------------------------------------------------- const dataColumns: ColumnDef[] = [ { accessorKey: "MATKL", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("MATKL") as string | null return (
{value || "-"}
) }, enableSorting: true, enableHiding: false, }, { accessorKey: "MATNR", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("MATNR") as string | null return (
{value || "-"}
) }, enableSorting: true, enableHiding: false, }, { accessorKey: "ZZNAME", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("ZZNAME") as string | null return (
{value || "-"}
) }, enableSorting: true, }, { accessorKey: "ZZPJT", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("ZZPJT") as string | null return (
{value || "-"}
) }, enableSorting: true, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("createdAt") as Date return (
{formatDate(value, "KR")}
) }, enableSorting: true, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("updatedAt") as Date return (
{formatDate(value, "KR")}
) }, enableSorting: true, }, ] // ---------------------------------------------------------------- // 3) actions 컬럼 (상세보기) // ---------------------------------------------------------------- const actionsColumn: ColumnDef = { id: "actions", enableHiding: false, cell: function Cell({ row }) { return ( ) }, size: 40, } // ---------------------------------------------------------------- // 4) 최종 컬럼 배열 // ---------------------------------------------------------------- return [ selectColumn, ...dataColumns, actionsColumn, ] }