Skip to content

Commit beabd1c

Browse files
authored
Merge pull request #101 from late4marshmellow/master
Enhance buildCell function to support object values with color styling
2 parents 7614aae + 78eb360 commit beabd1c

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

MMM-JsonTable.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,28 @@ Module.register("MMM-JsonTable", {
165165
buildCell (key, value) {
166166
const cell = document.createElement("td");
167167
let valueToDisplay = "";
168+
let cellValue = "";
169+
170+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
171+
if ("value" in value) {
172+
cellValue = value.value;
173+
} else {
174+
cellValue = "";
175+
}
176+
177+
if ("color" in value) {
178+
cell.style.color = value.color;
179+
}
180+
} else {
181+
cellValue = value;
182+
}
183+
168184
if (key === "icon") {
169-
cell.classList.add("fa", value);
185+
cell.classList.add("fa", cellValue);
170186
} else if (this.config.tryFormatDate) {
171-
valueToDisplay = this.getFormattedValue(value);
187+
valueToDisplay = this.getFormattedValue(cellValue);
172188
} else {
173-
valueToDisplay = value;
189+
valueToDisplay = cellValue;
174190
}
175191
let textContent = "";
176192
if (valueToDisplay === null || typeof valueToDisplay === "undefined") {

0 commit comments

Comments
 (0)