# Capture snapshot data for UI table

**URL:** <https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599>\
**Category:** General\
**Created:** [1 February 2022 15:41 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599 "2022-02-01T15:41:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WBr](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@WBr](https://discourse.nodered.org/u/WBr)\
**Post date:** [1 February 2022 15:41 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599/1 "2022-02-01T15:41:56Z")

</div>

I have been struggling with this UI table for a while

I have a sensor running. I would like to create a snapshot of the data (time and temperature) when a certain event is happening so I can store it in my UI table for later use.

I can press the button once and receive the data of one moment. But I need to add a different row per click instead of overwriting the previous data collection.

Could someone help me with adding new rows with new data everytime I hit a button?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/74f994fc248570d6a19b10e01424109d94463ff7.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64c7cb631a14eb107f9ec79bab7e217ae0ed3538.png)

```auto
[{"id":"547d6e73f83a51b5","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"64b4d7283483e209","type":"function","z":"547d6e73f83a51b5","name":"update or add to table","func":"\nvar temperature = msg.temperature;\nvar id = Number(msg.id);\nvar time = msg.time\n\nmsg.payload={\n command:\"updateOrAddData\",\n arguments: [\n [\n {\n \"id\": id,\n \"temperature\": temperature,\n \"time\": msg.time \n }\n]\n ],\n returnPromise: true\n}\n\n\n\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":1160,"wires":[["5ca6d5339f79fea9"]]},{"id":"5ca6d5339f79fea9","type":"ui_table","z":"547d6e73f83a51b5","group":"519d07fc52813146","name":"","order":1,"width":"0","height":"0","columns":[{"field":"id","title":"Fraction","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temperature","title":"Temperature ℃","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"time","title":"Time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":1590,"y":1160,"wires":[["4d58a5ca6b17999c"]]},{"id":"fca94b0ed091a778","type":"change","z":"547d6e73f83a51b5","name":"Change node","rules":[{"t":"set","p":"temperature","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"id","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1160,"wires":[["61758af6e2ec595d"]]},{"id":"342761b3b6e758d3","type":"change","z":"547d6e73f83a51b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1920,"y":1160,"wires":[[]]},{"id":"4d58a5ca6b17999c","type":"switch","z":"547d6e73f83a51b5","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"id","vt":"str"},{"t":"eq","v":"temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1730,"y":1160,"wires":[["342761b3b6e758d3"],["342761b3b6e758d3"]]},{"id":"2a35ee1ff4528f5d","type":"sensor-ds18b20","z":"547d6e73f83a51b5","name":"Temperature sensor","topic":"","sensorid":"28-00000003f09c","timer":"1","repeat":false,"x":360,"y":1160,"wires":[["fca94b0ed091a778"]]},{"id":"d724c08838cc9435","type":"inject","z":"547d6e73f83a51b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":140,"y":1140,"wires":[["2a35ee1ff4528f5d"]]},{"id":"aba6362d429af909","type":"debug","z":"547d6e73f83a51b5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2190,"y":600,"wires":[]},{"id":"26298d72780fc2c2","type":"string","z":"547d6e73f83a51b5","name":"","methods":[{"name":"toInteger","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2110,"y":1160,"wires":[[]]},{"id":"61758af6e2ec595d","type":"moment","z":"547d6e73f83a51b5","name":"Add time and date","topic":"","input":"","inputType":"date","inTz":"ETC/GMT","adjAmount":"2","adjType":"hours","adjDir":"add","format":"","locale":"nl_NL","output":"time","outputType":"msg","outTz":"Europe/Amsterdam","x":770,"y":1160,"wires":[["d2f7a7bdef458d4f"]]},{"id":"d2f7a7bdef458d4f","type":"function","z":"547d6e73f83a51b5","name":"add time and temperature to payload object","func":"msg.payload = {\n \"temperature\": Number(msg.payload),\n \"time\": msg.time \n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1070,"y":1160,"wires":[["64b4d7283483e209"]]},{"id":"e9a8b2eaf9ca9133","type":"ui_button","z":"547d6e73f83a51b5","name":"Data snapshot","group":"519d07fc52813146","order":29,"width":0,"height":0,"passthru":false,"label":"Data snapshot","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":190,"y":1240,"wires":[["2a35ee1ff4528f5d"]]},{"id":"519d07fc52813146","type":"ui_group","name":"Reageerbuis","tab":"8b21002.03afe","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"8b21002.03afe","type":"ui_tab","name":"Autosampler","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [1 February 2022 16:51 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599/2 "2022-02-01T16:51:59Z")

</div>

Perhaps you can get some insights how the row index works in this post and the complete thread

> [@Stop ui-table from auto-numbering column](https://discourse.nodered.org/t/stop-ui-table-from-auto-numbering-column/57159/6):
>
> Hi, As I see your table the data comes from measuring devices which should have any kind of unique id (I use the mqtt topic for all data comming in from mqtt devices or the serial number of others. Send this id with all your data {id:"device001",value:123.12} So if you send a new value later {id:"device001",value:999.99} using the updateOrAddData function call the value will be updated. Best practice is to send only the changed values to keep the traffic load low and be able to use something l…

I’m traveling so I can’t look into your flow soon. So you might provide a incremental index in your case (a timestamp for example) and declare this column as index. You can even hide this column if it isn’t useful to display

---

<div class="post-metadata">

**Author:** ![WBr](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@WBr](https://discourse.nodered.org/u/WBr)\
**Post date:** [1 February 2022 17:13 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599/3 "2022-02-01T17:13:46Z")

</div>

Thank-You for your reply

> [@Christian-Me](#):
>
> and declare this column as index

How?

Additional data:

"Add time and date" function node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c30411b5ce448d15b15a0c60fe1638a0e12668a0.png)

```auto
msg.payload = {
 "temperature": Number(msg.payload),
 "time": msg.time 
};

return msg;

"update or add to table" function node:

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c220d93955506e7297183a1cd46de16729b62321.png)

```auto

var temperature = msg.temperature;
var id = Number(msg.id);
var time = msg.time

msg.payload={
    command:"updateOrAddData",
    arguments: [
        [
            {
            "id": id,
            "temperature": temperature,
            "time": msg.time 
            }
        ]
    ],
    returnPromise: true
}

return msg;

```

---

<div class="post-metadata">

**Author:** ![WBr](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@WBr](https://discourse.nodered.org/u/WBr)\
**Post date:** [1 February 2022 17:23 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599/4 "2022-02-01T17:23:17Z")

</div>

I got it! It worked!

Thank you so much for the solution!

Every click gives a new row with updated data (the snapshot)

```auto
[{"id":"547d6e73f83a51b5","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"aba6362d429af909","type":"debug","z":"547d6e73f83a51b5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2190,"y":600,"wires":[]},{"id":"26298d72780fc2c2","type":"string","z":"547d6e73f83a51b5","name":"","methods":[{"name":"toInteger","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2110,"y":1160,"wires":[[]]},{"id":"583f6ec5db50e77b","type":"function","z":"547d6e73f83a51b5","name":"update or add to table","func":"\nvar temperature = msg.temperature;\nvar id = Number(msg.id);\nvar time = msg.time\n\nmsg.payload={\n command:\"updateOrAddData\",\n arguments: [\n [\n {\n \"id\": id,\n \"temperature\": temperature,\n \"time\": msg.time \n }\n]\n ],\n returnPromise: true\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1340,"y":880,"wires":[["9daf0e8a85fc6d47"]]},{"id":"9daf0e8a85fc6d47","type":"ui_table","z":"547d6e73f83a51b5","group":"519d07fc52813146","name":"","order":1,"width":"0","height":"0","columns":[{"field":"id","title":"Fraction","width":"","align":"left","formatter":"rownum","formatterParams":{"target":"_blank"}},{"field":"temperature","title":"Temperature ℃","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"time","title":"Time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":1550,"y":880,"wires":[["c273fd389cfbac56"]]},{"id":"6594d49db96f7393","type":"change","z":"547d6e73f83a51b5","name":"Change node","rules":[{"t":"set","p":"temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":880,"wires":[["cdf6bd88fa16f2cb"]]},{"id":"73637215f28cd63d","type":"change","z":"547d6e73f83a51b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1880,"y":880,"wires":[[]]},{"id":"c273fd389cfbac56","type":"switch","z":"547d6e73f83a51b5","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"id","vt":"str"},{"t":"eq","v":"temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1690,"y":880,"wires":[["73637215f28cd63d"],["73637215f28cd63d"]]},{"id":"238041217d8b935b","type":"sensor-ds18b20","z":"547d6e73f83a51b5","name":"Temperature sensor","topic":"","sensorid":"28-00000003f09c","timer":"1","repeat":false,"x":320,"y":880,"wires":[["6594d49db96f7393"]]},{"id":"85730631555de577","type":"inject","z":"547d6e73f83a51b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":860,"wires":[["238041217d8b935b"]]},{"id":"cdf6bd88fa16f2cb","type":"moment","z":"547d6e73f83a51b5","name":"Add time and date","topic":"","input":"","inputType":"date","inTz":"ETC/GMT","adjAmount":"2","adjType":"hours","adjDir":"add","format":"","locale":"nl_NL","output":"time","outputType":"msg","outTz":"Europe/Amsterdam","x":730,"y":880,"wires":[["699698564b877d19"]]},{"id":"699698564b877d19","type":"function","z":"547d6e73f83a51b5","name":"add time and temperature to payload object","func":"msg.payload = {\n \"temperature\": Number(msg.payload),\n \"time\": msg.time \n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1030,"y":880,"wires":[["583f6ec5db50e77b"]]},{"id":"ab4a342a10320cdb","type":"ui_button","z":"547d6e73f83a51b5","name":"Data snapshot","group":"519d07fc52813146","order":29,"width":0,"height":0,"passthru":false,"label":"Data snapshot","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":900,"wires":[["238041217d8b935b"]]},{"id":"519d07fc52813146","type":"ui_group","name":"Reageerbuis","tab":"8b21002.03afe","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"8b21002.03afe","type":"ui_tab","name":"Autosampler","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [15 February 2022 17:24 UTC](https://discourse.nodered.org/t/capture-snapshot-data-for-ui-table/57599/5 "2022-02-15T17:24:01Z")

</div>

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