fixed size column

This commit is contained in:
Claudio 2026-02-18 09:58:42 +01:00
parent ef8f2d8000
commit bdc4e0e60c

View File

@ -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 lutente 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 {