Examples for node-red-node-ui-table

Yes ... I use this function in my "remote device table"

image

to indicate the state of my remote devices.

{
    "tabulator": {
        "rowFormatter": "function(row){     var data = row.getData();     switch (data.$state) {         case \"lost\":             row.getElement().style.backgroundColor = \"#9e2e66\";             row.getElement().style.color = \"#a6a6a6\";             break;         case \"sleeping\":             row.getElement().style.backgroundColor = \"#336699\";             break;         case \"disconnected\":             row.getElement().style.backgroundColor = \"#cc3300\";             row.getElement().style.color = \"#a6a6a6\";             break;         case \"alert\":             row.getElement().style.backgroundColor = \"#A6A6DF\";             break;         case \"init\":             row.getElement().style.backgroundColor = \"#f2f20d\";             break;         case \"ready\":             row.getElement().style.backgroundColor = \"\";             row.getElement().style.color = \"\";             break;         } }",
    }
}
rowFormatter = function(row){
    var data = row.getData();
    switch (data.$state) {
        case "lost":
            row.getElement().style.backgroundColor = "#9e2e66";
            row.getElement().style.color = "#a6a6a6";
            break;
        case "sleeping":             
            row.getElement().style.backgroundColor = "#336699";             
            break;         
        case "disconnected":             
            row.getElement().style.backgroundColor = "#cc3300";             
            row.getElement().style.color = "#a6a6a6";             
            break;         
        case "alert":             
            row.getElement().style.backgroundColor = "#A6A6DF";             
            break;         
        case "init":             
            row.getElement().style.backgroundColor = "#f2f20d";             
            break;         
        case "ready":             
            row.getElement().style.backgroundColor = "";             
            row.getElement().style.color = "";             
            break;         
    }
}

It could be that your boolean values are not stored as boolean type. I would insert a debugger statement behind the row.getData() call and check what value and type data.value actually is. (I love the "beauty" of javascript)

3 Likes