[Example flow] Dashboard table node

Almost every question in the forums about using the table nodes results in suggesting that the examples be used as a way to get going.
The trouble with the examples is that they do not contain a msg.payload.
They simply have pre-formatted strings that 'just work' with the table node with no clues given as to how to get from a msg.payload to the required table format.

Since I am not a coder by nature, nurture or profession, it has taken me many (many) hours to figure out how to format my data to be displayed. So I hope what follows will help out others in much less time.

The example I have put together has three broad parts.
The msg.payload, in this case a raw (example) string from a process.
To format this string for the table, we first split and join it into an array.
Then lastly we format that array into a JSON object for the table.

Here is how the flow looks with each debug stage shown.

Depending on the format of your msg.payload you may need to change any part of the process.
The real key is that you want to end up with an array of a key:value pairs for the table to display.

To be clear, this example does not have an array of arrays, so only one value is shown in the example.
It looks like this....

(I ended up taking this flow, using what I had learned and putting the data into MySQL and then doing a select statement that got the last 10 records to fill out the table).

Depending on your needs there are a few different ways to store the table data. A forum search will guide you.

Here then is the flow.

[{"id":"e760b55b.7aed88","type":"inject","z":"ed1c87d4.0bf83","name":"","topic":"","payload":"OK;;203.208.65.21;US;United States of America;California;Melbourne;32412;40.7128;74.006;-09:00","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1010,"y":520,"wires":[["92ed6d5a.e101a8","c85e55cc.59a668"]]},{"id":"92ed6d5a.e101a8","type":"split","z":"ed1c87d4.0bf83","name":"split on ;","splt":";","spltType":"str","arraySplt":"11","arraySpltType":"len","stream":false,"addname":"","x":1160,"y":520,"wires":[["ef4d85b2.f2672"]]},{"id":"ef4d85b2.f2672","type":"join","z":"ed1c87d4.0bf83","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"11","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1330,"y":520,"wires":[["6b793448.d24704","a5ab60f5.5a39f8"]]},{"id":"e247a978.d3b958","type":"debug","z":"ed1c87d4.0bf83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1710,"y":460,"wires":[]},{"id":"6b793448.d24704","type":"function","z":"ed1c87d4.0bf83","name":"Array to JSON","func":"var IP,Country,State,Town; // declar the variables\n\n//get your data out of the previous array\nIP = msg.payload[2];\nCountry = msg.payload[4];\nState = msg.payload[5];\nTown = msg.payload[6];\n\n// create the JSON object for the table node.\nmsg.payload = ([{\"IP address\":IP,\"Country of origin\":Country,State:State,Town:Town}])\nreturn msg","outputs":1,"noerr":0,"x":1520,"y":520,"wires":[["e247a978.d3b958","c190c3ab.e997d8"]]},{"id":"c190c3ab.e997d8","type":"ui_table","z":"ed1c87d4.0bf83","group":"a0bc20ad.e7209","name":"","order":1,"width":10,"height":7,"columns":[],"outputs":0,"cts":false,"x":1690,"y":520,"wires":[]},{"id":"a5ab60f5.5a39f8","type":"debug","z":"ed1c87d4.0bf83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1510,"y":460,"wires":[]},{"id":"c85e55cc.59a668","type":"debug","z":"ed1c87d4.0bf83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":460,"wires":[]},{"id":"a0bc20ad.e7209","type":"ui_group","z":"","name":"IP List","tab":"787b32f4.1f680c","order":2,"disp":true,"width":10,"collapse":false},{"id":"787b32f4.1f680c","type":"ui_tab","z":"","name":"MySQL","icon":"dashboard","disabled":false,"hidden":false}]
8 Likes

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