From a6f0a2ef9af0a1dc83f1c17c11a9674ff5a88f2e Mon Sep 17 00:00:00 2001 From: TuanVT Date: Thu, 20 Aug 2026 18:07:25 +0700 Subject: [PATCH] feat-update --- src/components/customs/custom-table.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/customs/custom-table.tsx b/src/components/customs/custom-table.tsx index 4354a60..48e4d77 100644 --- a/src/components/customs/custom-table.tsx +++ b/src/components/customs/custom-table.tsx @@ -10,7 +10,7 @@ import { } from "lucide-react"; /* ================= TYPES ================= */ -interface ColumnType { +export interface ColumnType { title: string | React.ReactNode; render: (row: T, index: number, path?: number[]) => React.ReactNode; className?: string; @@ -23,7 +23,8 @@ interface ColumnType { interface PropsTable { data: T[]; - column: ColumnType[]; + // Cập nhật kiểu dữ liệu ở đây để chấp nhận thêm false | null | undefined + column: (ColumnType | false | null | undefined)[]; fixedHeader?: boolean; activeHeader?: boolean; handleCheckedAll?: (e: React.ChangeEvent) => void; @@ -38,7 +39,7 @@ interface PropsTable { /* ================= COMPONENT ================= */ export default function Table({ data, - column, + column: rawColumn, // Đổi tên prop column thành rawColumn fixedHeader, activeHeader, handleCheckedAll, @@ -52,6 +53,12 @@ export default function Table({ const tableRef = useRef(null); const thRefs = useRef<(HTMLTableCellElement | null)[]>([]); + // Lọc bỏ các giá trị falsy (false, null, undefined) để thu được mảng ColumnType[] hợp lệ + const column = useMemo( + () => rawColumn.filter((col): col is ColumnType => Boolean(col)), + [rawColumn], + ); + const [expandedRows, setExpandedRows] = useState([]); const [sortConfig, setSortConfig] = useState<{ key: string; @@ -172,7 +179,7 @@ export default function Table({ ); }); - /* ================= MOBILE CARDS (KHUÔN BẢNG GIỐNG ẢNH MẪU) ================= */ + /* ================= MOBILE CARDS ================= */ const renderMobileCards = (rows: T[], path: number[] = []): React.ReactNode => rows.map((row, i) => { const currentPath = [...path, i]; @@ -182,15 +189,12 @@ export default function Table({ return ( - {/* Khung Card cho mỗi bệnh nhân / dòng */}
{column.map((col, idx) => (
- {/* Tiêu đề bên trái (TÊN BỆNH NHÂN, MÃ PHIÊN KHÁM,...) */}
{col.checkBox && ( ({ {col.title}
- {/* Giá trị / Nút bấm bên phải */}
{col.render(row, i, currentPath)}
))} - {/* Xem thêm nếu có hàng con */} {getChildren && !!children?.length && (
- {/* Render hàng con nếu có */} {expanded && children && (
{renderMobileCards(children, currentPath)}