import React, { useState, useMemo } from 'react'; import { ExcelRow } from '../types'; interface MatrixViewProps { data: ExcelRow[]; headers: string[]; } export function MatrixView({ data, headers }: MatrixViewProps) { const [page, setPage] = useState(1); const [pageSize, setPageSize] = useState(25); const paginatedData = useMemo(() => { const start = (page - 1) * pageSize; return data.slice(start, start + pageSize); }, [data, page, pageSize]); const formatCellValue = (val: any, header: string = '') => { if (val === undefined || val === null || val === '') return ''; // Convert header to lowercase for checks const h = header.toLowerCase(); // Do NOT format columns that are clearly IDs, barcodes, or codes if (h.includes('id') || h.includes('no') || h.includes('code') || h.includes('art.') || h.includes('barcode') || h.includes('article')) { return val; } // List of keywords that typically indicate a price or numeric value to format const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk']; const isPriceCol = priceKeywords.some(kw => h.includes(kw)); // Handle numbers if (typeof val === 'number') { return val.toFixed(2); } // Handle strings that represent numbers if (typeof val === 'string') { // Normalize decimals (handle comma as decimal separator) const normalized = val.trim().replace(',', '.'); const num = parseFloat(normalized); if (!isNaN(num)) { // Format if it's a price column OR if it already has a decimal separator (.) if (isPriceCol || val.includes('.') || val.includes(',')) { return num.toFixed(2); } } } return val; }; const totalPages = Math.ceil(data.length / pageSize); return (

Matrix View

All data fields formatted to 2 decimal places for numbers/prices.

{headers.map((header, index) => ( ))} {paginatedData.map((row, rowIndex) => ( {headers.map((header, colIndex) => { const formattedValue = formatCellValue(row[colIndex], header); return ( ); })} ))} {paginatedData.length === 0 && ( )}
{header}
{formattedValue}
No data available.
Showing {Math.min((page - 1) * pageSize + 1, data.length)} to {Math.min(page * pageSize, data.length)} of {data.length} entries
Page {page} of {totalPages || 1}
); }