Node_red_node_ui_table help

Hello,
I am trying to use node_red_node_ui_table to display data from a network of sensors, using treedata format and nested headings.

I setup the table with the required column configuration and with some static row data.

My problem comes when I try to merge in live values in some of the fields in the rows. I t looks like I cannot update selected fields in a row by sending the row "id" and the fields I want to update. Nothings happens! Do I need to resend all the fields in the row to make this work? If not, what am I missing?

A test flow is given below

Roger

[{"id":"855eddf4.8bf1b","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"581b5710.b64848","type":"function","z":"855eddf4.8bf1b","name":"process_live_status","func":"// Update map markers and dashboard table\nvar payload = {\n    \"command\": \"updateOrAddData\",\n    \"arguments\": []\n};\nconsole.log(`topic ${msg.topic} payload ${JSON.stringify(msg.payload)}`)\nvar topic_split = msg.topic.split('/');\nconsole.log(`topic_split.length ${topic_split.length}`)\nvar address;\nvar sensor_slot;\nvar node_active;\nvar sensor_value;\nif (topic_split < 3 || topic_split > 4) {\n        console.log(`Invalid MQTT topic received ${msg.topic}`);\n        return\n}\n\nif (topic_split.length == 3) {\n    payload.arguments[0] = [{\n        \"id\": topic_split[2],\n        \"address\": topic_split[2],\n        \"active\": msg.payload.active\n    }]\n} else {\n    // It is a sensor line\n    payload.arguments[0] = [{\n        \"id\": topic_split[2] + '/' + topic_split[3],\n        \"value\": msg.payload.value\n    }]\n}\nmsg = {};\nmsg.payload = payload;\n\nconsole.log(`msg ${JSON.stringify(msg)}`);\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":400,"wires":[["254735f6.654e8a","5ea05eb.d01de2"]]},{"id":"5ea05eb.d01de2","type":"ui_table","z":"855eddf4.8bf1b","group":"399c97d.78c80e8","name":"test_status_table","order":1,"width":"20","height":"6","columns":[],"outputs":1,"cts":true,"x":910,"y":180,"wires":[["72d590e9.fc80e"]]},{"id":"254735f6.654e8a","type":"debug","z":"855eddf4.8bf1b","name":"input_to_table","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1100,"y":400,"wires":[]},{"id":"fe9e362b.152aa8","type":"comment","z":"855eddf4.8bf1b","name":"Set up live table","info":"","x":340,"y":120,"wires":[]},{"id":"b20ca337.abf6b","type":"function","z":"855eddf4.8bf1b","name":"setup_live_table","func":"let node_dbid_to_mesh_address_map = new Map();\nlet node_dbid_to_slots_map = new Map();\n\nmsg.ui_control = {\n    \"tabulator\": {\n        \"height\": \"100%\",\n        \"dataTree\": true,\n        \"dataTreeStartExpanded\":true,\n        \"columns\": [\n            { \"title\": \"id\", \"field\": \"id\", \"visible\": true, \"sorter\": \"alphanum\"},\n            { \"title\": \"Name\", \"field\": \"name\", \"align\": \"left\"},\n            { \"title\": \"Active\", \"field\": \"active\", \"hozAlign\":\"center\", \"formatter\":\"tickCross\", \"align\": \"center\"},\n            { \"title\": \"Sensors\", \"columns\": [\n                { \"title\": \"Sensor slot\", \"field\": \"sensor_slot\"},\n                { \"title\": \"Sensor name\", \"field\": \"sensor_name\"},\n                { \"title\": \"Value\", \"field\": \"value\"}\n            ]}\n        ],\n        \"data\": []\n    }\n}\n\nvar node_results = msg.payload[0];\nvar sensor_results = msg.payload[1];\n\nnode_results.forEach(function (result){\n     // Populate a node row\n    msg.ui_control.tabulator.data.push({\n        \"id\": result.properties.mesh_address,\n        \"name\": result.properties.name\n    });\n    // Populate node dbid to address map\n    let idString = result._id.toString();\n    node_dbid_to_mesh_address_map.set(idString, result.properties.mesh_address);\n\n    // Populate node dbid to sensor slots map\n    let sensor_slots = new Map();\n    let i = 0;\n    result.properties.node_inputs.forEach(function (input){\n        sensor_slots.set(input.toString(), i);\n        i++;\n    });\n    node_dbid_to_slots_map.set(idString, sensor_slots);\n});\n\n// This relies on nodes being processed first\nsensor_results.forEach(function (result){\n    //Populate a sensor row\n    let myId = result._id.toString();\n    let parentId = result.properties.parent.toString();\n    let mesh_address = node_dbid_to_mesh_address_map.get(parentId);\n    let slots = node_dbid_to_slots_map.get(parentId);\n    let slot = slots.get(myId)\n    msg.ui_control.tabulator.data.push({\n        \"id\": mesh_address + '/' + slot,\n        \"sensor_slot\": slot,\n        \"sensor_name\": result.properties.name\n    });\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":180,"wires":[["5ea05eb.d01de2","bf55e9cb.32bbf"]]},{"id":"bf55e9cb.32bbf","type":"debug","z":"855eddf4.8bf1b","name":"setup_live_table","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1140,"y":80,"wires":[]},{"id":"72d590e9.fc80e","type":"debug","z":"855eddf4.8bf1b","name":"table_output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":180,"wires":[]},{"id":"eb3c8d06.5c42c","type":"debug","z":"855eddf4.8bf1b","name":"incomimg_merged_query","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":300,"wires":[]},{"id":"ee007015.c4aaa","type":"inject","z":"855eddf4.8bf1b","name":"node_active","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"marchwoodinternational/epping/0A.6B.A9","payload":"{\"active\":1}","payloadType":"json","x":350,"y":400,"wires":[["581b5710.b64848","1da718a6.e8ce87"]]},{"id":"1da718a6.e8ce87","type":"debug","z":"855eddf4.8bf1b","name":"injection","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":580,"y":520,"wires":[]},{"id":"bed7f483.145d5","type":"inject","z":"855eddf4.8bf1b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[{\"_id\":\"607555dab5fd1005d123469e\",\"type\":\"Feature\",\"properties\":{\"type\":\"Node\",\"name\":\"Kitchen\",\"mesh_address\":\"0A.6B.A9\",\"node_inputs\":[\"6075880cb5fd1005d123469f\"]},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.85315161943436,50.8694597985755]}},{\"_id\":\"607588d6b5fd1005d12346a0\",\"type\":\"Feature\",\"properties\":{\"type\":\"Node\",\"name\":\"Dining Room\",\"mesh_address\":\"10.10.4\",\"node_inputs\":[\"607593a0b5fd1005d12346a1\"]},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.85288473963738,50.869557975861]}}],[{\"_id\":\"6075880cb5fd1005d123469f\",\"type\":\"Feature\",\"properties\":{\"type\":\"Sensor\",\"name\":\"Fridge\",\"parent\":\"607555dab5fd1005d123469e\",\"slot\":null,\"alarm\":false,\"sensor_type\":false,\"digital_alarm_trigger\":false,\"analog_alarm_low_value\":\"50\",\"analog_alarm_high_value\":50,\"analog_alarm_invert\":false},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.85311540961266,50.869427637006]}},{\"_id\":\"607593a0b5fd1005d12346a1\",\"type\":\"Feature\",\"properties\":{\"type\":\"Sensor\",\"name\":\"Bum on seat\",\"parent\":\"607588d6b5fd1005d12346a0\",\"slot\":null,\"alarm\":false,\"sensor_type\":true,\"digital_alarm_trigger\":false,\"analog_alarm_low_value\":\"50\",\"analog_alarm_high_value\":50,\"analog_alarm_invert\":false},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.85293570160866,50.8695063481763]}}],[{\"_id\":\"60591f3aedb3bd05a3ef0f0d\",\"type\":\"Feature\",\"properties\":{\"type\":\"Location\",\"name\":\"Marchwood\"},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-1.8531650304794314,50.86935231113786],[-1.8530215322971346,50.869254133419176],[-1.8531194329261782,50.86919911995195],[-1.8531315028667452,50.86920758356653],[-1.8531703948974612,50.86918727088897],[-1.8532253801822665,50.86922281806886],[-1.853187829256058,50.86924482345238],[-1.8532669544219973,50.86929560506697],[-1.8531650304794314,50.86935231113786]]]}},{\"_id\":\"60609bd77600274ced753d4d\",\"type\":\"Feature\",\"properties\":{\"type\":\"Location\",\"name\":\"Fred\"},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-1.8545120334859866,50.86953010191799],[-1.8543173777052526,50.869418424503245],[-1.8545580430341582,50.86927994413737],[-1.8547279244428185,50.86940502319551],[-1.8545120334859866,50.86953010191799]]]}},{\"_id\":\"6075545ab5fd1005d123469c\",\"type\":\"Feature\",\"properties\":{\"name\":\"Chez Jim\"},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-1.8528295494552909,50.8697437768504],[-1.8525049334810095,50.869532041414814],[-1.852992946757779,50.86923643513962],[-1.8533066695785607,50.86944817191793],[-1.8532565610724765,50.869477045040455],[-1.8532935977943656,50.869492169049884],[-1.8533240986241675,50.86953616614031],[-1.8532478465496731,50.869581538096305],[-1.85317595173657,50.86956366430072],[-1.853119307338378,50.869527916689016],[-1.8529580886665853,50.86962828491388],[-1.852979874973584,50.86964615868466],[-1.8528295494552909,50.8697437768504]]]}},{\"_id\":\"6076f99bbb9d4305faa507c2\",\"type\":\"Feature\",\"properties\":{\"name\":\"newloc\"},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-1.8539929382490319,50.86907144477554],[-1.8537903255939383,50.86907144477554],[-1.8536400000756452,50.86886933078366],[-1.8542195158418195,50.868903703973366],[-1.8539929382490319,50.86907144477554]]]}},{\"_id\":\"6076f9b2bb9d4305faa507c3\",\"type\":\"Feature\",\"properties\":{\"name\":\"newloc\"},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-1.8539929382490319,50.86907144477554],[-1.8537903255939383,50.86907144477554],[-1.8536400000756452,50.86886933078366],[-1.8542195158418195,50.868903703973366],[-1.8539929382490319,50.86907144477554]]]}}],[{\"_id\":\"606dbe0a139876a2aa067127\",\"name\":\"Marchwood Rotated\",\"url\":\"http://localhost:8901/marchwood.jpg\",\"bounds\":[[50.8692154,-1.853422],[50.8698307,-1.8524509]],\"opt\":{\"opacity\":0.8},\"type\":\"image\"}]]","payloadType":"json","x":290,"y":180,"wires":[["b20ca337.abf6b"]]},{"id":"399c97d.78c80e8","type":"ui_group","name":"Group 1","tab":"2803c11a.ff639e","order":1,"disp":true,"width":"20","collapse":false},{"id":"2803c11a.ff639e","type":"ui_tab","name":"Tab 4","icon":"dashboard","order":4}]

Roger,

I checked the output and found something I could not place in your original code:


Removing that makes it work rather nice:
image

I like the way you do this and might use it for my own purposes.

Good luck

Thanks for the catch #AsHex_66. I had missed that!

Just got to work out how to blank out the spurious x in the sensor rows now.

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