[Solved] How to change timestamps in objects to date/time for ui_table

Hi,

I would let ui-table (tabulator) do the formatting. This would ensure that sorting, filtering and all other features work as expected. Moment.js features are build into the dashboard (at least in my installations).
You can use msg.ui_control to activated the build in datetime formatter:

{
    "tabulator": {
        "columns": [
            {
                "formatter": "datetime",
                "formatterParams": {
                    "inputFormat": "x",
                    "outputFormat": "DD. MMMM YYYY hh:mm:ss",
                    "invalidPlaceholder": "(invalid date)"
                },
                "title": "Last Seen",
                "field": "last_seen"
            }
        ]
    }
}

gives you this
image

[{"id":"d29f47f1.983ac8","type":"inject","z":"bfc08422.a451e8","name":"Data in Payload","topic":"","payload":"[{\"last_action\":\"msg\",\"last_seen\":1592070983674,\"location\":\"testing\",\"mqtt_mode\":\"local\",\"node_id\":\"node28\",\"node_status\":\"sleep\",\"sleep_time\":0},{\"last_action\":\"msg\",\"last_seen\":1592070444879,\"location\":\"greenhouse\",\"mqtt_mode\":\"local\",\"node_id\":\"node42\",\"node_status\":\"sleep\",\"sleep_time\":0},{\"last_action\":\"msg\",\"last_seen\":1592070734128,\"location\":\"basement\",\"mqtt_mode\":\"local\",\"node_id\":\"node44\",\"node_status\":\"sleep\",\"sleep_time\":0}]","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":285,"y":221,"wires":[["d54c7a85.46e848"]]},{"id":"dc0c2b3c.bd0a88","type":"ui_table","z":"bfc08422.a451e8","group":"68300045.dcdbf","name":"table","order":2,"width":"12","height":"7","columns":[],"outputs":1,"cts":true,"x":675,"y":221,"wires":[["c6384aa1.cbe018"]]},{"id":"d54c7a85.46e848","type":"change","z":"bfc08422.a451e8","name":"ui_control","rules":[{"t":"set","p":"ui_control","pt":"msg","to":"{\"tabulator\":{\"columns\":[{\"formatter\":\"datetime\",\"formatterParams\":{\"inputFormat\":\"x\",\"outputFormat\":\"DD. MMMM YYYY hh:mm:ss\",\"invalidPlaceholder\":\"(invalid date)\"},\"title\":\"Last Seen\",\"field\":\"last_seen\"},{\"title\":\"Action\",\"field\":\"last_action\"},{\"title\":\"Location\",\"field\":\"location\"},{\"title\":\"MQTT node\",\"field\":\"mqtt_mode\"},{\"title\":\"Id\",\"field\":\"node_id\"},{\"title\":\"Status\",\"field\":\"node_status\"},{\"title\":\"sleep\",\"field\":\"sleep_time\"}]}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":502,"y":221,"wires":[["dc0c2b3c.bd0a88"]]},{"id":"c6384aa1.cbe018","type":"debug","z":"bfc08422.a451e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":832,"y":221,"wires":[]},{"id":"68300045.dcdbf","type":"ui_group","z":"","name":"Device Status","tab":"baf5f94f.3685c8","order":1,"disp":true,"width":"12","collapse":false},{"id":"baf5f94f.3685c8","type":"ui_tab","z":"","name":"Status table","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

If you format one column you should format all other columns too. (More examples for using ui_control are in the examples including custom formatters) and more about tabulator formatters and other features you find here:

2 Likes