From bdc4e0e60c004eba22205cd598f275af47c8dae1 Mon Sep 17 00:00:00 2001 From: solocla Date: Wed, 18 Feb 2026 09:58:42 +0100 Subject: [PATCH] fixed size column --- public/userarea/import_edit2.php | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php index ef9e987..7c6e09c 100644 --- a/public/userarea/import_edit2.php +++ b/public/userarea/import_edit2.php @@ -1723,6 +1723,63 @@ function fixedDefaultValue(array $f): string } }); }); + // === AUTO WIDTH BY HEADER LABEL (initial only) === + function autoFitColumnsByHeader({ + minPx = 150, + maxPx = 380, + extraPx = 40, // padding + resizer + un po' di aria + ignoreIndexes = [] // es: [1,2] se vuoi escludere main/client ecc + } = {}) { + + // misura testo in modo affidabile + function measureTextWidth(text, font) { + const canvas = measureTextWidth._canvas || (measureTextWidth._canvas = document.createElement("canvas")); + const ctx = canvas.getContext("2d"); + ctx.font = font; + return ctx.measureText(text).width; + } + + // prendi tutti gli header con data-index + const headers = document.querySelectorAll(".grid-row .grid-header[data-index]"); + headers.forEach(header => { + + const idx = parseInt(header.getAttribute("data-index"), 10); + if (!idx || ignoreIndexes.includes(idx)) return; + + // se l’utente ha già ridimensionato manualmente, non tocchiamo più + if (header.dataset.userResized === "1") return; + + // testo label pulito (toglie il resizer dal calcolo) + const text = (header.childNodes[0]?.textContent || header.textContent || "").trim(); + + // font reale dell'header per la misura + const cs = window.getComputedStyle(header); + const font = `${cs.fontStyle} ${cs.fontVariant} ${cs.fontWeight} ${cs.fontSize} / ${cs.lineHeight} ${cs.fontFamily}`; + + const wText = measureTextWidth(text, font); + const desired = Math.max(minPx, Math.min(maxPx, Math.ceil(wText + extraPx))); + + // applica a header + cells + top cells + const selHeader = `.grid-header[data-index="${idx}"]`; + const selCell = `.grid-cell[data-index="${idx}"]`; + const selTop = `.grid-top .grid-cell[data-index="${idx}"]`; + + document.querySelectorAll(selHeader).forEach(el => el.style.flex = `0 0 ${desired}px`); + document.querySelectorAll(selCell).forEach(el => el.style.flex = `0 0 ${desired}px`); + document.querySelectorAll(selTop).forEach(el => el.style.flex = `0 0 ${desired}px`); + }); + } + + requestAnimationFrame(() => { + setTimeout(() => { + autoFitColumnsByHeader({ + minPx: 150, + maxPx: 380, + extraPx: 40, + ignoreIndexes: [] + }); + }, 50); + }); // Gestione del ridimensionamento delle colonne const resizers = document.querySelectorAll('.resizer'); @@ -1749,6 +1806,8 @@ function fixedDefaultValue(array $f): string const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`); const topCells = document.querySelectorAll(`.grid-top .grid-cell[data-index="${columnIndex}"]`); headers.forEach(header => header.style.flex = `0 0 ${newWidth}px`); + headers.forEach(header => header.dataset.userResized = "1"); + cells.forEach(cell => cell.style.flex = `0 0 ${newWidth}px`); topCells.forEach(cell => cell.style.flex = `0 0 ${newWidth}px`); } @@ -1835,9 +1894,17 @@ function fixedDefaultValue(array $f): string populateDropdowns(); }); + autoFitColumnsByHeader({ + minPx: 150, + maxPx: 380, + extraPx: 40, + ignoreIndexes: [] // lascia vuoto per applicare a tutte le colonne indicizzate + }); + document.addEventListener("DOMContentLoaded", function() { let clientData = []; + async function loadClients(retryCount = 0, maxRetries = 3) { const clientLoadingStatus = document.getElementById("clientLoadingStatus"); try {