How to avoid deselect of row if table only has one row?

How to avoid deselect of row if table only has one row? The following works the selected row the background color is changed as desired when there are two rows or more.

But I want the background of a single/pre-selected row to not change to the light grey default, when there is only one signal row in table, it should stay set to the background color I pre-set.

Just not sure how to establish that logic. Any help appreciated. Full disclosure, I replicated this logic from an example found, so I am not entirely sure I understand exactly how it works.

[{"id":"a6a578233309e348","type":"inject","z":"b1227818064dcd74","name":"Test 2 Rows","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{},{}]","payloadType":"jsonata","x":130,"y":780,"wires":[["a0e81e23aab3d9de"]]},{"id":"b14e877856f4476b","type":"ui_table","z":"b1227818064dcd74","group":"7142a0cbbf2229fc","name":"Test","order":0,"width":0,"height":0,"columns":[{"field":"","title":"Test","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":710,"y":800,"wires":[["3b6444522905368e"]]},{"id":"a0e81e23aab3d9de","type":"link out","z":"b1227818064dcd74","name":"","mode":"link","links":["095c19a242b575a9"],"x":255,"y":800,"wires":[]},{"id":"ce6f0a933a4409c9","type":"link in","z":"b1227818064dcd74","name":"","links":["bfcdf1cf35908b94","55034c3deea34781"],"x":605,"y":800,"wires":[["b14e877856f4476b"]]},{"id":"38090529732abce1","type":"debug","z":"b1227818064dcd74","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1140,"y":800,"wires":[]},{"id":"86a421d929881b47","type":"link in","z":"b1227818064dcd74","name":"","links":["bfcdf1cf35908b94"],"x":1025,"y":800,"wires":[["38090529732abce1"]]},{"id":"91fdc77f479ccfe4","type":"inject","z":"b1227818064dcd74","name":"Test 1 Rows","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{}]","payloadType":"jsonata","x":130,"y":820,"wires":[["a0e81e23aab3d9de"]]},{"id":"240957d651d8d249","type":"function","z":"b1227818064dcd74","name":"Select","func":"msg.ui_control = {\n    \"tabulator\": {\n        \"selectable\":1,\n        \"renderComplete\":\"function(){this.send({ui_control:{callback:'renderComplete'}})}\"\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":800,"wires":[["55034c3deea34781"]]},{"id":"3b6444522905368e","type":"function","z":"b1227818064dcd74","name":"Select","func":"if (msg.hasOwnProperty('ui_control') && msg.ui_control.callback === \"renderComplete\") {\n    \n    var msgOut={\n        \n        payload:{\n            \n            command:\"selectRow\",\n            arguments: [0],\n            returnPromise: false\n        }\n        \n    }\n    \n    return msgOut;\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":800,"wires":[["bfcdf1cf35908b94"]]},{"id":"095c19a242b575a9","type":"link in","z":"b1227818064dcd74","name":"","links":["a0e81e23aab3d9de"],"x":325,"y":800,"wires":[["240957d651d8d249"]]},{"id":"55034c3deea34781","type":"link out","z":"b1227818064dcd74","name":"","mode":"link","links":["ce6f0a933a4409c9"],"x":535,"y":800,"wires":[]},{"id":"bfcdf1cf35908b94","type":"link out","z":"b1227818064dcd74","name":"","mode":"link","links":["ce6f0a933a4409c9","86a421d929881b47"],"x":955,"y":800,"wires":[]},{"id":"7142a0cbbf2229fc","type":"ui_group","name":"Default","tab":"13ecdbb1ece78207","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"13ecdbb1ece78207","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Hi .. you know how many rows you are sending ( msg.payload.length) so ..
if the rows are more that 1 make rows selectable : true otherwise if its only 1 false
(havent played around with it extensively .. dont know if it breaks any of the expected functionality)

msg.ui_control = {
    "tabulator": {
        "selectable": msg.payload.length > 1 ? true : false,
        "renderComplete":"function(){this.send({ui_control:{callback:'renderComplete'}})}"
    }
};

return msg;

Thats ok, I will test it pretty extensively.

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