"use client"; import React from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Checkbox } from "@/components/ui/checkbox"; import { ArrowUp, ArrowDown, ArrowUpDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { ColumnConfig } from "./types"; interface SingleTableWithStickyProps { visibleColumns: ColumnConfig[]; data: Record[]; columnLabels: Record; sortColumn: string | null; sortDirection: "asc" | "desc"; tableConfig: any; isDesignMode: boolean; isAllSelected: boolean; handleSort: (columnName: string) => void; handleSelectAll: (checked: boolean) => void; handleRowClick: (row: any) => void; renderCheckboxCell: (row: any, index: number) => React.ReactNode; formatCellValue: (value: any, format?: string, columnName?: string) => string; getColumnWidth: (column: ColumnConfig) => number; joinColumnMapping: Record; // 조인 컬럼 매핑 추가 } export const SingleTableWithSticky: React.FC = ({ visibleColumns, data, columnLabels, sortColumn, sortDirection, tableConfig, isDesignMode, isAllSelected, handleSort, handleSelectAll, handleRowClick, renderCheckboxCell, formatCellValue, getColumnWidth, joinColumnMapping, }) => { const checkboxConfig = tableConfig.checkbox || {}; return (
{visibleColumns.map((column, colIndex) => { // 왼쪽 고정 컬럼들의 누적 너비 계산 const leftFixedWidth = visibleColumns .slice(0, colIndex) .filter((col) => col.fixed === "left") .reduce((sum, col) => sum + getColumnWidth(col), 0); // 오른쪽 고정 컬럼들의 누적 너비 계산 const rightFixedColumns = visibleColumns.filter((col) => col.fixed === "right"); const rightFixedIndex = rightFixedColumns.findIndex((col) => col.columnName === column.columnName); const rightFixedWidth = rightFixedIndex >= 0 ? rightFixedColumns.slice(rightFixedIndex + 1).reduce((sum, col) => sum + getColumnWidth(col), 0) : 0; return ( column.sortable && handleSort(column.columnName)} >
{column.columnName === "__checkbox__" ? ( checkboxConfig.selectAll && ( ) ) : ( <> {columnLabels[column.columnName] || column.displayName || column.columnName} {column.sortable && ( {sortColumn === column.columnName ? ( sortDirection === "asc" ? ( ) : ( ) ) : ( )} )} )}
); })}
{data.length === 0 ? ( 데이터가 없습니다 ) : ( data.map((row, index) => ( handleRowClick(row)} > {visibleColumns.map((column, colIndex) => { // 왼쪽 고정 컬럼들의 누적 너비 계산 const leftFixedWidth = visibleColumns .slice(0, colIndex) .filter((col) => col.fixed === "left") .reduce((sum, col) => sum + getColumnWidth(col), 0); // 오른쪽 고정 컬럼들의 누적 너비 계산 const rightFixedColumns = visibleColumns.filter((col) => col.fixed === "right"); const rightFixedIndex = rightFixedColumns.findIndex((col) => col.columnName === column.columnName); const rightFixedWidth = rightFixedIndex >= 0 ? rightFixedColumns.slice(rightFixedIndex + 1).reduce((sum, col) => sum + getColumnWidth(col), 0) : 0; return ( {column.columnName === "__checkbox__" ? renderCheckboxCell(row, index) : (() => { // 🎯 매핑된 컬럼명으로 데이터 찾기 (기본 테이블과 동일한 로직) const mappedColumnName = joinColumnMapping[column.columnName] || column.columnName; // 조인 컬럼 매핑 정보 로깅 if (column.columnName !== mappedColumnName && index === 0) { console.log(`🔗 Sticky 조인 컬럼 매핑: ${column.columnName} → ${mappedColumnName}`); } const cellValue = row[mappedColumnName]; if (index === 0) { // 첫 번째 행만 로그 출력 (디버깅용) console.log( `🔍 Sticky 셀 데이터 [${column.columnName} → ${mappedColumnName}]:`, cellValue, ); } return formatCellValue(cellValue, column.format, column.columnName) || "\u00A0"; })()} ); })} )) )}
); };