Stop ui-table from auto-numbering column

Hi,

As I see your table the data comes from measuring devices which should have any kind of unique id (I use the mqtt topic for all data comming in from mqtt devices or the serial number of others. Send this id with all your data {id:"device001",value:123.12}
So if you send a new value later {id:"device001",value:999.99} using the updateOrAddData function call the value will be updated. Best practice is to send only the changed values to keep the traffic load low and be able to use something like this Ui-table: highlight updated cells with animations

Using your demo if you inject your data you always get a new row. I did a little modification so you can see how to use the id field to be able to send updates (see the "Power Usage" column each time you inject the row.

[{"id":"ea700dd5acd0970d","type":"inject","z":"790d116ed3ca1bf0","name":"Load 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Stove\",\"priority\":0,\"type\":\"AC\",\"ratedPower\":800,\"powerUsage\":735,\"state\":\"active\"}","payloadType":"json","x":230,"y":220,"wires":[["5b9ce9155c66e437"]]},{"id":"02824747a9095989","type":"inject","z":"790d116ed3ca1bf0","name":"Load 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Microwave\",\"priority\":4,\"type\":\"AC\",\"ratedPower\":1100,\"powerUsage\":0,\"state\":\"inactive\"}","payloadType":"json","x":230,"y":260,"wires":[["5b9ce9155c66e437"]]},{"id":"9f16c188d6f4ae7d","type":"inject","z":"790d116ed3ca1bf0","name":"Load 3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"TV\",\"priority\":5,\"type\":\"AC\",\"ratedPower\":150,\"powerUsage\":150,\"state\":\"disabled\"}","payloadType":"json","x":230,"y":300,"wires":[["5b9ce9155c66e437"]]},{"id":"69b0b1cc8d07a904","type":"inject","z":"790d116ed3ca1bf0","name":"Load 4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Refrigerator\",\"priority\":1,\"type\":\"DC\",\"ratedPower\":600,\"powerUsage\":25,\"state\":\"active\"}","payloadType":"json","x":230,"y":340,"wires":[["5b9ce9155c66e437"]]},{"id":"a6db6cf161f2417a","type":"inject","z":"790d116ed3ca1bf0","name":"Load 5","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Kitchen Light\",\"priority\":2,\"type\":\"DC\",\"ratedPower\":25,\"powerUsage\":24.8,\"state\":\"active\"}","payloadType":"json","x":230,"y":380,"wires":[["5b9ce9155c66e437"]]},{"id":"4ae69d337884f3f2","type":"inject","z":"790d116ed3ca1bf0","name":"Load 6","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Laptop\",\"priority\":3,\"type\":\"AC\",\"ratedPower\":90,\"powerUsage\":0,\"state\":\"inactive\"}","payloadType":"json","x":230,"y":420,"wires":[["5b9ce9155c66e437"]]},{"id":"5b9ce9155c66e437","type":"function","z":"790d116ed3ca1bf0","name":"Format For Table","func":"var tableRow = {\n    command: \"updateOrAddData\",\n    arguments: [\n        [\n            {\n                id: msg.payload.priority,\n                priority: msg.payload.priority,                \n                loadName: msg.payload.name,\n                type: msg.payload.type,\n                ratedPower: msg.payload.ratedPower,\n                powerUsage: (Math.random()*100).toFixed(1),\n                state: msg.payload.state\n            }  \n        ]\n    ],\n    returnPromise: true\n};\n\n// Replace the status strings with icons to go in the table\nif (tableRow.arguments[0][0].state == \"active\")\n    tableRow.arguments[0][0].state = '<i class=\"material-icons icon-2x\" style=\"color: navy;\">check_circle</i>';\nelse if (tableRow.arguments[0][0].state == \"inactive\")\n    tableRow.arguments[0][0].state = '<i class=\"material-icons icon-2x\" style=\"color: gray;\">check_circle_outline</i>';\nelse if (tableRow.arguments[0][0].state == \"disabled\")\n    tableRow.arguments[0][0].state = '<i class=\"material-icons icon-2x\" style=\"color: red;\">dnd_forwardslash</i>';\nelse\n    tableRow.arguments[0][0].state = '<i class=\"material-icons icon-2x\" style=\"color: gray;\">radio_button_unchecked</i>';\n    \nmsg.payload = tableRow;\nnode.warn(tableRow.arguments[0][0].priority);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":320,"wires":[["b49f7c86dfee2597"]]},{"id":"b49f7c86dfee2597","type":"ui_table","z":"790d116ed3ca1bf0","group":"be4515129be2c1be","name":"Load Priority Table","order":6,"width":20,"height":8,"columns":[{"field":"priority","title":"Priority","width":"11%","align":"center","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"loadName","title":"Load Name","width":"28%","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"type","title":"Type","width":"9%","align":"center","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"ratedPower","title":"Rated Power (W)","width":"20%","align":"center","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"powerUsage","title":"Power Usage (W)","width":"22%","align":"center","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"state","title":"State","width":"9%","align":"center","formatter":"html","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":730,"y":320,"wires":[["6ddf301a207840fa"]]},{"id":"6ddf301a207840fa","type":"debug","z":"790d116ed3ca1bf0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":320,"wires":[]},{"id":"be4515129be2c1be","type":"ui_group","name":"Controls","tab":"11bccd3d1bb29d0f","order":2,"disp":false,"width":"22","collapse":false},{"id":"11bccd3d1bb29d0f","type":"ui_tab","name":"Power - Load Prioritization","icon":"dashboard","order":13,"disabled":false,"hidden":false}]

Adding the id don't change the sorting. you can always sort the table as you wish, either by using the header controls or by command, config ... more info here

msg.payload = {
    command: "setSort",
    arguments: [
        [
            {
                column: "priority",                
                dir: "asc",
            }  
        ]
    ],
    returnPromise: false
};

(not tested, I think you get the idea)

To enable sorting you have to configure your table. As the config dialog don't include this option you have to add this by sending a ui_control message Ui-table supports ui_control

I found out that you have to trigger sorting after each new row (don't know if I did something wrong but I could not see any sorting after a updateOrAddData command

Yeah! That's a challenge but possible:
image

But before that have you recognized that you loose all table data when you switch tabs? That's because the table is destroyed when disconnected or another tab is selected!

You have to replay your data every time the table becomes visible (unless you you have sent it as a complete table. But then you already have collected all data and changes before). And if you like to have movable rows you have to track the order too. That is where I can suggest to take a look into my ui-table-handler subflow which take care of all of these (and much more):

image

You can find the latest incarnation + demo here: Get ui-table data in JSON format - #11 by Christian-Me (a basic documentation is included)