Ui-table display update

I run into a strange problem and need some help here :sweat_smile:
I am using ui-table to display sensor information. Somehow, the ui-table information is not updated until I refresh the browser. I write a test code here and it is very simple. The table information should be updated every 3 seconds. But somehow, the updated information can only be shown by refreshing the browser :sweat_smile: What could be wrong?

[{"id":"26642e55.a6fd32","type":"inject","z":"c8985bd5.a4f9f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":700,"wires":[["d30ffc62.0fcab"]]},{"id":"d30ffc62.0fcab","type":"function","z":"c8985bd5.a4f9f8","name":"Sensor info","func":"var buf=msg.payload;\nvar temp=flow.get(\"table1\");\nif(temp==null)\n    {temp=[\n      {\"row\": 1,\n            \"id\": 1,\n            \"property\": \"hello\",\n            \"uptime\":new Date().toLocaleString()\n        },\n       {\"row\": 2,\n            \"id\": 2,\n            \"property\": \"yolo\",\n            \"uptime\":new Date().toLocaleString()\n        }\n    ]}\n\ntemp[0]=  {\"row\": 1,\n        \"id\": 1,\n        \"property\": buf.toString(),\n        \"uptime\":new Date().toLocaleString()\n    };\n\n\nflow.set(\"table1\",temp);\nmsg.payload=temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":720,"wires":[["547b7dd6.a76474","768fe06d.0f123"]]},{"id":"547b7dd6.a76474","type":"ui_table","z":"c8985bd5.a4f9f8","group":"3b02597c.184f36","name":"Test","order":3,"width":0,"height":0,"columns":[{"field":"id","title":"Label","width":"","align":"left","formatter":"rownum","formatterParams":{"target":"_blank"}},{"field":"property","title":"Property","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"uptime","title":"Update time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":600,"y":680,"wires":[]},{"id":"768fe06d.0f123","type":"debug","z":"c8985bd5.a4f9f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":740,"wires":[]},{"id":"3b02597c.184f36","type":"ui_group","name":"Sensor info","tab":"1d1ac0f7.0858bf","order":1,"disp":false,"width":"18","collapse":false},{"id":"1d1ac0f7.0858bf","type":"ui_tab","name":"Sensor Info","icon":"dvr","order":10,"disabled":false,"hidden":false}]

There are multiple ways to do this. Here is one way by adding a slight delay while sending a [] in the payload ui-table then the updated table. Try this

[{"id":"26642e55.a6fd32","type":"inject","z":"327bb595.c533fa","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":140,"wires":[["d30ffc62.0fcab"]]},{"id":"d30ffc62.0fcab","type":"function","z":"327bb595.c533fa","name":"Sensor info","func":"var buf=msg.payload;\nvar temp=flow.get(\"table1\");\nif(temp==null)\n    {temp=[\n      {\"row\": 1,\n            \"id\": 1,\n            \"property\": \"hello\",\n            \"uptime\":new Date().toLocaleString()\n        },\n       {\"row\": 2,\n            \"id\": 2,\n            \"property\": \"yolo\",\n            \"uptime\":new Date().toLocaleString()\n        }\n    ]}\n\ntemp[0]=  {\"row\": 1,\n        \"id\": 1,\n        \"property\": buf.toString(),\n        \"uptime\":new Date().toLocaleString()\n    };\n\n\nflow.set(\"table1\",temp);\nmsg.payload=temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":180,"wires":[["768fe06d.0f123","da15ac4f.9bad58","68991337.6ea7ec"]]},{"id":"547b7dd6.a76474","type":"ui_table","z":"327bb595.c533fa","group":"3b02597c.184f36","name":"Test","order":3,"width":0,"height":0,"columns":[{"field":"id","title":"Label","width":"","align":"left","formatter":"rownum","formatterParams":{"target":"_blank"}},{"field":"property","title":"Property","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"uptime","title":"Update time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":750,"y":160,"wires":[]},{"id":"768fe06d.0f123","type":"debug","z":"327bb595.c533fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":290,"y":260,"wires":[]},{"id":"da15ac4f.9bad58","type":"delay","z":"327bb595.c533fa","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":530,"y":220,"wires":[["547b7dd6.a76474"]]},{"id":"68991337.6ea7ec","type":"change","z":"327bb595.c533fa","name":"clear out the table","rules":[{"t":"set","p":"payload","pt":"msg","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":160,"wires":[["547b7dd6.a76474"]]},{"id":"3b02597c.184f36","type":"ui_group","name":"Sensor info","tab":"1d1ac0f7.0858bf","order":1,"disp":false,"width":"18","collapse":false},{"id":"1d1ac0f7.0858bf","type":"ui_tab","name":"Sensor Info","icon":"dvr","order":10,"disabled":false,"hidden":false}]
2 Likes

Thank you very much. It looks like the uitable has to be cleared first, and then it can be updated automatically. This solved my problem.

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