Ui-table, msg.ui_control formatters

Hello all,

I am looking for advice with using the node-red-node-ui-table node. I would like to set the BG color of cells in a column that have the value of true. I cannot seem to find the correct formatter or the formatters that are available dont seem to work in the way I expect. using this function to set the column params in a msg.ui_control field does not seem to do anything at all.

msg.ui_control = {tabulator: {columns:[  
    {
        "field": "vals",
        "width": "30%",
        "editor": false,
        "formatter": "function(cell, formatterParams){ var value = cell.getValue(); if (value === false) { cell.getElement().css({ 'background-color': '#D31772' }); } return value; }"
    } 
]
}
}
node.send(msg)
return ;

Finally found an example that I was able to make sense of. Or maybe taking a break and coming back to it and the formatters and examples are clearer to me.. either way. this works
CleanShot 2023-04-22 at 23.01.01

msg.ui_control = {
    tabulator: {
        headerVisible: false,
        rowFormatter: (function (row) {
            const data = row.getData();
            if (data.vals) {
                row.getElement().style.backgroundColor = 'red';
            } else {
                row.getElement().style.backgroundColor = '';
            }
        }).toString(),
        columns: [
            {
                field: "vals",
                width: "30%",
                editor: false,
            }
        ]
    }
};

msg.payload = null;
node.send(msg);
return;
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.