Get data from ui_table

Hi there,

I am trying to pass the data displayed in the ui_table to the payload.
I have tried to use tabulator's table.getData() command but I didn't manage to get any result in the payload.

I am sending the command this way:

msg.payload={
command:"getData",
arguments: ,
}

Any help about this issue?

Thanks in advance,
Aitor

Have you taken a look at th examples for that node?

I'm assuming you want to return a single row and not the entire table (since you actually pass add the data into the ui-table node in the first place). Have you ckecked off the 'Send data on click` option?

Hi there, thanks for responding.

Yes, actually I tested the flows of the examples on Christian's github. Following the examples I can add, clear rows etc.
I also enabled 'send data on click' and this sends be back the row I selected. However I wanted to have back the entire table, any clues about how can it be done?

Thanks,
Aitor

@Christian-Me I'm at a loss :anguished: have you any ideas?

Hi ... I don't think there is a command available to "export" the hole table content.

I use my ui-table handler subflow to take care of all the tasks around ui-table.

it holds a copy of your table-data, tabel edits and table config (useful for replay on browser reconnects)

image

and you can export the table context too ... (merged tableEdit into tableData)

this is the latest Version:
https://flows.nodered.org/flow/35d0480ce9151b2a722fa9d185a37825

You can find it in my homie-device-table and syslog-server. (older versions)

a msg.payload.command="getTable" should give you the table array on the second output

The doc (help tab) is not 100% up to date but should do the task

1 Like

Hi Christian,

Nice solution yours!

However, it was not suitable for me since I wanted to get he data that was directly written in the table, so I could not save that input in your handler's buffer.
I came up with an alternative that is suitable for my application. Whenever I select the row of the table, the table returns which is the currently selected row. And once the data of the row has been edited it also returns a 'cellEditedCallback'. So knowing which was the latest selected row and the edited value I can update my table buffer with the correspondig new value. This way, I update individually each row whenever it has been edited.

I'm leaving solution here:

[{"id":"dd57457f.f1874","type":"function","z":"dbb19b25.93c07","name":"Define Table","func":"value_list = context.flow.get(\"values_list\")\ncolumns_list = context.flow.get(\"column_list\")\ntable = []\n\n// Define Content\nfor (i=0; i<columns_list.length;i++){\n    column_name = columns_list[i]\n    value = value_list[i]\n    table[i]=Object.assign({ENTRY_NAME:column_name,VALUE:value})\n}\nmsg.payload = table\ncontext.flow.set(\"table\",table)\n\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":968,"wires":[["d933ab86.c1e148"]]},{"id":"d933ab86.c1e148","type":"function","z":"dbb19b25.93c07","name":"Table UI","func":"//Define Table Control\nmsg.ui_control =  {\n    \"tabulator\":{\n        \"columnResized\":\"function(column){var newColumn = {         field: column._column.field,         visible: column._column.visible,         width: column._column.width,         widthFixed: column._column.widthFixed,         widthStyled: column._column.widthStyled     }; this.send({topic:this.config.topic,ui_control:{callback:'columnResized',columnWidths:newColumn}}); }\",\n        \"columnMoved\":\"function(column, columns){     var newColumns=[];     columns.forEach(function (column) {         newColumns.push({'field': column._column.field});     });     this.send({topic:this.config.topic,ui_control:{callback:'columnMoved',columns:newColumns}}); }\",\n        \"groupHeader\":\"function (value, count, data, group) {return value + \\\"<span style='color:#d00; margin-left:10px;'>(\\\" + count + \\\" Termostat\\\"+((count>1) ? \\\"e\\\" : \\\"\\\") + \\\")</span>\\\";}\",\n        \"columns\":[\n            {\"formatterParams\":{\"target\":\"_blank\"},\"title\":\"Entry Name\",\"field\":\"ENTRY_NAME\",\"align\":\"left\"},\n            {\"formatterParams\":{\"target\":\"_blank\"},\"title\":\"Value\",\"field\":\"VALUE\",\"align\":\"left\", \"editor\":\"input\"},\n\n        ],\n        \n        \"cellEdited\":\"function(cell){var change = {newValue:cell.getValue()};this.send({topic:this.config.topic,ui_control:{callback:'cellEdited',changes:change}});}\",\n        \"layout\":\"fitColumns\",\n        \"movableColumns\":true,\n        \"groupBy\":\"\"\n    },\n}\nreturn msg;","outputs":1,"noerr":0,"x":348,"y":968,"wires":[["38f4ab6d.1e5e34"]]},{"id":"38f4ab6d.1e5e34","type":"ui_table","z":"dbb19b25.93c07","group":"ff5ded58.80b7b8","name":"","order":1,"width":24,"height":"9","columns":[{"field":"ENTRY_NAME","title":"Entry Name","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"VALUE","title":"Value","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":490,"y":968,"wires":[["1ce60da5.e86912"]]},{"id":"1ce60da5.e86912","type":"function","z":"dbb19b25.93c07","name":"Define Selected Entry","func":"if (msg.topic === 'VALUE'){\n    context.flow.set(\"selected_entry\",msg.payload.ENTRY_NAME)\n}\nreturn msg;","outputs":1,"noerr":0,"x":668,"y":968,"wires":[["2d75fdf9.c1754a"]]},{"id":"2d75fdf9.c1754a","type":"function","z":"dbb19b25.93c07","name":"Update Data","func":"// Update Table Data Buffer\nselected_entry = context.flow.get(\"selected_entry\")\ntable = context.flow.get(\"table\")\n\nif (msg.ui_control.callback === 'cellEdited'){\n    new_val = msg.ui_control.changes.newValue\n    for (i=0; i<table.length;i++){\n        if(table[i].ENTRY_NAME === selected_entry){\n            table[i].VALUE = new_val\n        }\n    }   \n}\nreturn msg;","outputs":1,"noerr":0,"x":862,"y":968,"wires":[[]]},{"id":"ff5ded58.80b7b8","type":"ui_group","z":"","name":"Recipe Table","tab":"64e5b49a.2728cc","order":3,"disp":false,"width":"24","collapse":false},{"id":"64e5b49a.2728cc","type":"ui_tab","z":"","name":"Recipe Management","icon":"subject","order":3,"disabled":false,"hidden":true}]

Thanks for your help! @zenofmud @Christian-Me