UNPKG

@ackplus/react-tanstack-data-table

Version:

A powerful React data table component built with MUI and TanStack Table

58 lines (57 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateSkeletonRows = calculateSkeletonRows; exports.generateRowId = generateRowId; exports.calculatePinnedColumnsWidth = calculatePinnedColumnsWidth; exports.shouldUseFixedLayout = shouldUseFixedLayout; exports.formatCellValue = formatCellValue; exports.debounce = debounce; exports.calculateTableMetrics = calculateTableMetrics; function calculateSkeletonRows(containerHeight, rowHeight, maxRows = 10) { const estimatedRows = Math.ceil(containerHeight / rowHeight); return Math.min(estimatedRows, maxRows); } function generateRowId(row, index, idKey) { if (idKey && row[idKey]) { return String(row[idKey]); } return `row-${index}`; } function calculatePinnedColumnsWidth(columns, side) { return columns .filter(col => col.getIsPinned() === side) .reduce((total, col) => total + (col.getSize() || 0), 0); } function shouldUseFixedLayout(fitToScreen, enableColumnResizing, totalColumns) { return fitToScreen || (enableColumnResizing && totalColumns > 5); } function formatCellValue(value, type) { if (value === null || value === undefined) { return '-'; } switch (type) { case 'date': return value instanceof Date ? value.toLocaleDateString() : String(value); case 'number': return typeof value === 'number' ? value.toLocaleString() : String(value); case 'boolean': return value ? 'Yes' : 'No'; default: return String(value); } } function debounce(func, wait) { let timeout; return (...args) => { clearTimeout(timeout); timeout = setTimeout(() => func(...args), wait); }; } function calculateTableMetrics(totalRows, visibleRows, columns, renderStartTime) { return { totalRows, visibleRows, pinnedColumns: columns.filter(col => col.getIsPinned()).length, renderTime: performance.now() - renderStartTime, }; }