correction du bug de coloration
This commit is contained in:
@@ -29,12 +29,16 @@
|
|||||||
}
|
}
|
||||||
// Tu peux ajouter d’autres règles ici si besoin
|
// Tu peux ajouter d’autres règles ici si besoin
|
||||||
];
|
];
|
||||||
|
|
||||||
// 🎨 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;
|
||||||
ths.forEach((th, index) => {
|
ths.forEach((th, index) => {
|
||||||
@@ -44,26 +48,38 @@
|
|||||||
targetIndex = index;
|
targetIndex = index;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
const rawText = cell.textContent.trim();
|
||||||
if (isNaN(value)) return;
|
const numeric = parseFloat(rawText.replace('%', '').replace(',', '.'));
|
||||||
|
|
||||||
for (const threshold of rule.thresholds) {
|
if (rule.matchText) {
|
||||||
if (value >= threshold.min) {
|
if (rawText.toUpperCase().includes(rule.matchText.toUpperCase())) {
|
||||||
cell.style.backgroundColor = threshold.color;
|
Object.entries(rule.style).forEach(([prop, val]) => {
|
||||||
cell.style.color = threshold.text;
|
cell.style[prop] = val;
|
||||||
cell.style.fontWeight = 'bold';
|
});
|
||||||
break;
|
}
|
||||||
|
} 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 c’est un chiffre
|
// alignement à droite si numérique
|
||||||
cell.classList.add('numeric');
|
if (!isNaN(numeric)) {
|
||||||
|
cell.classList.add("numeric");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user