# A very standard ui-table situation

**URL:** https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947
**Category:** Dashboard
**Created:** [3 March 2021 11:06 UTC](https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947 "2021-03-03T11:06:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ceysa75](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceysa75/32/31340_2.png) [@ceysa75](https://discourse.nodered.org/u/ceysa75)
#### Post date: [3 March 2021 11:06 UTC](https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947/1 "2021-03-03T11:06:23Z")

</div>

Dear All,

I have a very standard situation where I have multiple temperature/humidity sensors which are distributed in our apartment. I just want to feed the payloads into a ui-table. Important to mention that the sensors do only report when changes in temperature/humidity are registered. And this is what I want to have, just to update the table (and ony the respective cells) if required.

However, my basic problem starts earlier: How can I get both sensors in the example below feed into ui-table ? Please look at my example flow. Is it really required to generate an 'arrayed' payload first ?

```auto
[{"id":"5d3de8db.f734e8","type":"inject","z":"2beb2f2e.99868","name":"Output_Sensor_1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"humidity\":42.9,\"temperature\":21.74}","payloadType":"json","x":180,"y":1390,"wires":[["89f58166.2e746"]]},{"id":"65e29898.2f6a28","type":"inject","z":"2beb2f2e.99868","name":"Output_Sensor_2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"humidity\":53.8,\"temperature\":23.41}","payloadType":"json","x":180,"y":1440,"wires":[["47ab2e50.f98bd"]]},{"id":"89f58166.2e746","type":"change","z":"2beb2f2e.99868","name":"","rules":[{"t":"set","p":"payload.room","pt":"msg","to":"Room 1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":1390,"wires":[["c622219b.20832"]]},{"id":"47ab2e50.f98bd","type":"change","z":"2beb2f2e.99868","name":"","rules":[{"t":"set","p":"payload.room","pt":"msg","to":"Room 2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":1440,"wires":[["c622219b.20832"]]},{"id":"c622219b.20832","type":"function","z":"2beb2f2e.99868","name":"manipulate payload","func":"var t = Math.round(msg.payload.temperature*10)/10; // Temperature\nvar h = Math.round(msg.payload.humidity); // Humidity\nvar r = msg.payload.room; // Room\n\nvar msg1 = { payload: [{ room:r, temp: t, humid: h }]};\nreturn msg1;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":1410,"wires":[["8bc1cbe9.84e9c8"]]},{"id":"8bc1cbe9.84e9c8","type":"ui_table","z":"2beb2f2e.99868","group":"4b41a1fd.e0159","name":"mytable","order":1,"width":"6","height":"4","columns":[{"field":"room","title":"Room","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temp","title":"Temperature","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"humid","title":"Humidity","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":880,"y":1410,"wires":[]},{"id":"9107512f.eb64","type":"comment","z":"2beb2f2e.99868","name":"Outputs of Sensor1 and Sensor2 not simultaneous","info":"","x":260,"y":1340,"wires":[]},{"id":"4b41a1fd.e0159","type":"ui_group","name":"Group 5","tab":"29ec6908.552b36","order":5,"disp":true,"width":6},{"id":"29ec6908.552b36","type":"ui_tab","name":"Table_UI_TEST","icon":"track_changes","order":8,"disabled":false,"hidden":false}]

```

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

Thanks in advance

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [3 March 2021 12:29 UTC](https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947/2 "2021-03-03T12:29:42Z")

</div>

> [@ceysa75](#):
>
> Is it really required to generate an 'arrayed' payload first ?

Not really, but it is easier to generate an array with the full table. Alternatively you could use [tabulator commands](http://tabulator.info/docs/4.9/update#addrow) to update individual rows. The ui\_table documentation explains [how to issue tabulator commands](https://github.com/node-red/node-red-ui-nodes/tree/master/node-red-node-ui-table) to the node.

If you want to go to the easier route here is how it could be done.

1- Generate a data structure that is easier to work with. I would create an object like the one below. It is straightforward to update this data structure with your data.

![r-1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97c2e401bafa2e5ea08160072618f259e8c96f7f.jpeg)

2- Add a function node to modify your data structure to the array format required by the ui\_table node. It is quite easy with jsonata but you can go with javascript if you want to. You should end up with an array like this one.

![r-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2b34737f91857257b5895ec9f41cef0f350180d.jpeg)

Here is how you table will display in the dashboard:

![r-3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6264e92010a3a2bb265501a1bc7dfceeab36387e.jpeg)

Code:

```auto
[{"id":"cbe143b3.14b06","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ff82eac1.97cf48","type":"inject","z":"cbe143b3.14b06","name":"Output_Sensor_1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"humidity\":42.9,\"temperature\":21.74}","payloadType":"json","x":300,"y":200,"wires":[["f9a24427.b1da88"]]},{"id":"68e050b9.9ee73","type":"inject","z":"cbe143b3.14b06","name":"Output_Sensor_2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"humidity\":53.8,\"temperature\":23.41}","payloadType":"json","x":300,"y":250,"wires":[["cbe45d87.fcb53"]]},{"id":"cbe45d87.fcb53","type":"change","z":"cbe143b3.14b06","name":"","rules":[{"t":"set","p":"payload.room","pt":"msg","to":"Room2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":250,"wires":[["e7a74899.5e6338"]]},{"id":"e7a74899.5e6338","type":"function","z":"cbe143b3.14b06","name":"manipulate payload","func":"var t = Math.round(msg.payload.temperature*10)/10; // Temperature\nvar h = Math.round(msg.payload.humidity); // Humidity\nvar r = msg.payload.room; // Room\n\nlet room = global.get(\"room\") || {} ;\n\nroom[r] = { \"temp\" : t, \"humid\" : h , \"room\" : r};\n\nglobal.set(\"room\" , room);\n\nmsg.payload = room;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":790,"y":220,"wires":[["a92778e.fc58388"]]},{"id":"3e2b2225.92171e","type":"ui_table","z":"cbe143b3.14b06","group":"46394dc6.651624","name":"mytable","order":1,"width":"6","height":"4","columns":[{"field":"room","title":"Room","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temp","title":"Temperature","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"humid","title":"Humidity","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":1180,"y":220,"wires":[]},{"id":"7388db54.963164","type":"comment","z":"cbe143b3.14b06","name":"Outputs of Sensor1 and Sensor2 not simultaneous","info":"","x":380,"y":150,"wires":[]},{"id":"ea3afeb8.59b73","type":"debug","z":"cbe143b3.14b06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":160,"wires":[]},{"id":"f9a24427.b1da88","type":"change","z":"cbe143b3.14b06","name":"","rules":[{"t":"set","p":"payload.room","pt":"msg","to":"Room1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":200,"wires":[["e7a74899.5e6338"]]},{"id":"a92778e.fc58388","type":"change","z":"cbe143b3.14b06","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":220,"wires":[["3e2b2225.92171e","ea3afeb8.59b73"]]},{"id":"46394dc6.651624","type":"ui_group","name":"Group 5","tab":"54a84fff.34561","order":5,"disp":true,"width":6},{"id":"54a84fff.34561","type":"ui_tab","name":"Table_UI_TEST","icon":"track_changes","order":8,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![ceysa75](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceysa75/32/31340_2.png) [@ceysa75](https://discourse.nodered.org/u/ceysa75)
#### Post date: [3 March 2021 15:44 UTC](https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947/3 "2021-03-03T15:44:48Z")

</div>

Dear Andrei,

good approach using global context. Thanks.  
I will continue based on that (eventually keeping all in one function node instead of using JSONata).  
Nevertheless, the JSONata command is a nice one 🙂 -\> I understand what it does but I don't understand why 🙂

Thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [17 March 2021 15:45 UTC](https://discourse.nodered.org/t/a-very-standard-ui-table-situation/41947/4 "2021-03-17T15:45:01Z")

</div>

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