# Help in Function Node - Dynamic Table properties (CSV to HTML)

**URL:** <https://discourse.nodered.org/t/help-in-function-node-dynamic-table-properties-csv-to-html/94751>\
**Category:** General\
**Tags:** function-node, foreach\
**Created:** [20 January 2025 04:42 UTC](https://discourse.nodered.org/t/help-in-function-node-dynamic-table-properties-csv-to-html/94751 "2025-01-20T04:42:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 January 2025 11:51 UTC](https://discourse.nodered.org/t/help-in-function-node-dynamic-table-properties-csv-to-html/94751/5 "2025-01-20T11:51:35Z")

</div>

You could replace it like;

```auto
let html = ""
html += "<!doctype html><html lang='en'>"
html += "<style>body{font-family:arial;}.running{background:#22c55e;color:#fff;}.not-running{background:#ef4444;color:#fff;}table{border-collapse:collapse}td,th{border:1px solid #999;padding:4px;font-size:12px;}</style>"
html += `<h3>Online Downtime Report (Hosur) for the date ${msg.ddate}</h3>`
html += "<table>"
html += "<thead><tr><th>Machine</th><th>Time-From</th><th>Time-To</th><th>Duration</th><th>Reason 1</th><th>Reason 2</th></tr></thead>"
html += "<tbody>"

msg.payload.forEach((part) => {
    if (part.col2 === undefined) {
        const css_class = part.col1.match("not running") ? "not-running" : 'running'
        html += `<tr><td colspan='6' class='${css_class}'>${part.col1}</td></tr>`
        
    } else if (part.col1 !== 'Machine') {
        const machine = msg.payload.filter(x=>x.col1.startsWith("SUM")).find(x=>x.col1.match(".*"+part.col1+".*"))
      
        let css_class = "running" 
        if (machine && machine.col1.match('not running') ){
            css_class = "not-running" 
        }
        html += `<tr class="${css_class}"><td>${part.col1}</td><td>${part.col2}</td><td>${part.col3}</td><td>${part.col4}</td><td>${part.col5}</td><td>${part.col6}</td></tr>`
    }
})
html += "</tbody></table></html>"

msg.payload = html
return msg

```

note that I made use of styles and apply them where applicable.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae6c44c1f131c78138188a6be1a21bcd6a3c30df.png)

Note I would recommend to start with different input data.  
The input already contains the sum, which originates from somewhere.

---

_[View the full topic](https://discourse.nodered.org/t/help-in-function-node-dynamic-table-properties-csv-to-html/94751)._
