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

**URL:** <https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121>\
**Category:** General\
**Created:** [19 June 2022 03:56 UTC](https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121 "2022-06-19T03:56:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [19 June 2022 03:56 UTC](https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121/1 "2022-06-19T03:56:26Z")

</div>

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.

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 June 2022 06:08 UTC](https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121/2 "2022-06-19T06:08:47Z")

</div>

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)

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

return msg;

```

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [19 June 2022 06:17 UTC](https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121/3 "2022-06-19T06:17:50Z")

</div>

Thats ok, I will test it pretty extensively.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 August 2022 06:18 UTC](https://discourse.nodered.org/t/how-to-avoid-deselect-of-row-if-table-only-has-one-row/64121/4 "2022-08-18T06:18:29Z")

</div>

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