Problem updating UI-Table

Hi, I have unexpected results with the following code in a function node. I have a table node behind this function node, but the table only updates when I refresh the browser, so the data is getting there in the correct format, but for some reason, the table is not updating when new data arrives.

Any help would be greatly appreciated.

var distanceFromBle = Math.pow(10, (-54 - (msg.payload.brssi)) / (10 * 3.5)).toFixed(1);

tableData = flow.get("savedData") || [];

tableData.unshift({
    "bmac" : msg.payload.bmac,
    "apmac": msg.payload.apmac,
    "mymac": msg.payload.mymac,
    "ltime": msg.payload.ltime,
    "wrssi": msg.payload.wrssi,
    "brssi": msg.payload.brssi,
    "distance": distanceFromBle
});


if (tableData.length > 9) tableData.pop();

msg.payload = tableData;

flow.set("savedData", tableData);

return msg;

I believe the issue is when you try to add a row, best use the command function addRow , there is info in the help text, there are also example flows in the import examples.

here is an example, i have hardcoded the incoming values, so you will need to edit

[{"id":"f772e294cac42fef","type":"ui_ui_control","z":"b9860b4b9de8c8da","name":"","events":"connect","x":100,"y":2960,"wires":[["4830d675874b086f"]]},{"id":"4830d675874b086f","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"savedData","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":2960,"wires":[["57590ede03d46c80"]]},{"id":"57590ede03d46c80","type":"ui_table","z":"b9860b4b9de8c8da","group":"2d4fe667.28f8ba","name":"","order":24,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":410,"y":3020,"wires":[]},{"id":"1340d3a79960f451","type":"function","z":"b9860b4b9de8c8da","name":"function 25","func":"let distanceFromBle = Math.pow(10, (-54 - (Math.random()*20)) / (10 * 3.5)).toFixed(1);\n\nlet tableData = flow.get(\"savedData\") || [];\nlet new_row = {\n    \"bmac\": tableData.length,\n    \"apmac\": 2,\n    \"mymac\": 2,\n    \"ltime\": 2,\n    \"wrssi\": 2,\n    \"brssi\": 2,\n    \"distance\": distanceFromBle\n};\n\ntableData.unshift(new_row);\nif (tableData.length > 9) tableData.pop();\n\nmsg.payload = {\n    command: \"addRow\",\n    arguments: [\n        new_row,\n        true\n    ],\n    returnPromise: true\n}\n\nflow.set(\"savedData\", tableData);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":3060,"wires":[["57590ede03d46c80","c896bb713eec327c"]]},{"id":"14ac1f7d6efe1fa3","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"one\":1,\"two\":2},{\"one\":4,\"two\":5}]","payloadType":"json","x":90,"y":3040,"wires":[["1340d3a79960f451"]]},{"id":"c896bb713eec327c","type":"debug","z":"b9860b4b9de8c8da","name":"debug 297","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":3080,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false,"className":""},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

[edit] Added Ui-control to load table on connect.

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