correction du bug de coloration

This commit is contained in:
Yacine31
2025-04-17 00:59:04 +02:00
parent a2aaffcd86
commit da4bc80fad

View File

@@ -33,7 +33,11 @@
// 🎨 Appliquer les règles de coloration dynamiquement // 🎨 Appliquer les règles de coloration dynamiquement
const colorizeDynamicColumns = () => { const colorizeDynamicColumns = () => {
document.querySelectorAll("table").forEach(table => { document.querySelectorAll("table").forEach(table => {
const ths = table.querySelectorAll("thead th"); const rows = table.querySelectorAll("tr");
if (rows.length === 0) return;
const headerRow = rows[0];
const ths = headerRow.querySelectorAll("th");
rules.forEach(rule => { rules.forEach(rule => {
let targetIndex = -1; let targetIndex = -1;
@@ -46,24 +50,36 @@
}); });
if (targetIndex !== -1) { if (targetIndex !== -1) {
table.querySelectorAll("tbody tr").forEach(row => { rows.forEach((row, i) => {
if (i === 0) return; // skip header
const cell = row.children[targetIndex]; const cell = row.children[targetIndex];
if (!cell) return; if (!cell) return;
const text = cell.textContent.trim().replace('%', '').replace(',', '.');
const value = parseFloat(text);
if (isNaN(value)) return;
for (const threshold of rule.thresholds) { const rawText = cell.textContent.trim();
if (value >= threshold.min) { const numeric = parseFloat(rawText.replace('%', '').replace(',', '.'));
cell.style.backgroundColor = threshold.color;
cell.style.color = threshold.text; if (rule.matchText) {
cell.style.fontWeight = 'bold'; if (rawText.toUpperCase().includes(rule.matchText.toUpperCase())) {
break; Object.entries(rule.style).forEach(([prop, val]) => {
cell.style[prop] = val;
});
}
} else if (!isNaN(numeric)) {
for (const threshold of rule.thresholds) {
if (numeric >= threshold.min) {
cell.style.backgroundColor = threshold.color;
cell.style.color = threshold.text;
cell.style.fontWeight = 'bold';
break;
}
} }
} }
// Alignement à droite aussi si cest un chiffre // alignement à droite si numérique
cell.classList.add('numeric'); if (!isNaN(numeric)) {
cell.classList.add("numeric");
}
}); });
} }
}); });