Simple ui_table to sort "desc" on load

It should actually be easy, but I don't have the right view!
A block of strings with ("date", "value1", "value2") has to be sorted and displayed in a table (ui_table). Sorting should take place at load in descending order according to "date".
A flow without sort setting always displays the "date" column as ascending.
sortedtable

All my attempts with ui_control/tabulator fail. Surely it should be "simple"? But how ... please help

I tried it with this:

msg.ui_control = {
    "tabulator": {
        column: "date", dir: "desc" }
    }

... but failed.

The 'Tabulator' has something like this function:

   table.setSort("age", "asc");

I also don't know how to use it with ui_table/ui_control

If you are using node-red-node-ui-table
this example shows how to use commands.

[{"id":"36be75f0.115c6a","type":"ui_button","z":"51e5d3061e86059f","name":"","group":"c91332c0.50c11","order":1,"width":0,"height":0,"passthru":false,"label":"Init 20 rows","tooltip":"init table by passing the hole table array (default way)","color":"","bgcolor":"","className":"","icon":"","payload":"20","payloadType":"num","topic":"","topicType":"str","x":264,"y":894,"wires":[["d4dce9b4.1f2588"]]},{"id":"d4dce9b4.1f2588","type":"function","z":"51e5d3061e86059f","name":"table with n rows as array","func":"var numberOfRows = msg.payload;\nflow.set(\"lastId\",numberOfRows);\nmsg.payload=[];\nfor (let i=1; i<=numberOfRows; i++) {\n    msg.payload.push({\"id\":i,\"timestamp\":Date.now(),\"text\":\"this is line\"+i})\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":525,"y":894,"wires":[["f9bfd98.abe1a28","69241bdcfcf2980c"]]},{"id":"12606591.7a3dca","type":"inject","z":"51e5d3061e86059f","name":"Init 20 rows","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":264,"y":928,"wires":[["d4dce9b4.1f2588"]]},{"id":"f9bfd98.abe1a28","type":"debug","z":"51e5d3061e86059f","name":"addRow","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":840,"wires":[]},{"id":"69241bdcfcf2980c","type":"ui_table","z":"51e5d3061e86059f","group":"c91332c0.50c11","name":"","order":2,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":570,"y":1000,"wires":[]},{"id":"eb577b4b.510388","type":"function","z":"51e5d3061e86059f","name":"addRow @ top","func":"msg.payload={\n    command:msg.topic,\n    arguments: [\n        msg.payload\n    ]\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":495,"y":1064,"wires":[["b54f6ce8.3b1a4","69241bdcfcf2980c"]],"info":"# addRow([row],onTop)\n\n`onTop=true`\n\nadds a new Row on top of the table"},{"id":"b496aa6a.32f2d8","type":"ui_button","z":"51e5d3061e86059f","name":"sort","group":"c91332c0.50c11","order":2,"width":0,"height":0,"passthru":false,"label":"sort","tooltip":"add a new row to the top","color":"","bgcolor":"","className":"","icon":"","payload":"[{\"column\":\"timestamp\",\"dir\":\"asc\"},{\"column\":\"text\",\"dir\":\"desc\"}]","payloadType":"json","topic":"setSort","topicType":"str","x":244,"y":1064,"wires":[["eb577b4b.510388"]]},{"id":"b54f6ce8.3b1a4","type":"debug","z":"51e5d3061e86059f","name":"addRow","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":520,"y":1120,"wires":[]},{"id":"c91332c0.50c11","type":"ui_group","name":"commands","tab":"379a501f.53b59","order":2,"disp":true,"width":"6","collapse":false},{"id":"379a501f.53b59","type":"ui_tab","name":"ui-table command","icon":"fa-table","disabled":false,"hidden":false}]

or you can can use initial sort with the ui_control.tabulatore property

Or
you can set a sort parameter to the column settings

p.s. the tabulator in ui-table is 4.4 documentation.

Looks like I got a good guide with this. :star_struck:
Unfortunately my search was not so successful!
Thanks! :wave:

Just had the opportunity to successfully test a "function" adapted to my situation on the basis of your example. My function equivalent to "table with n rows as array" and "addRow @ top" is this one:
sortingtable

msg.payload = tabledata;
node.send(msg);

msg.payload = {
    command: "setSort",
    arguments: [
        [{ "column": "date", "dir": "desc" }]
    ]
}
return (msg);

I first send the data with the function using node.send(msg) and then the control for sorting the "date" column with the send(msg);
Maybe it works in one approach, but this way it is clear and simple for me

Thanks again for the help.

It is exactly the same approach, my example was set out so you could see it work in the dashboard. As you offered no flow example with data to adapt i created data to use in a demonstration.

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