# How to trap or determine when a row is deselected in ui-table?

**URL:** <https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293>\
**Category:** Dashboard\
**Created:** [4 January 2024 16:28 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293 "2024-01-04T16:28:29Z")\
**Posts on this page:** 7\
**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:** [4 January 2024 16:28 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/1 "2024-01-04T16:28:29Z")

</div>

How to trap or determine when a row is deselected ui-table?

I have a use case where I need to know if a row is deselected by the operator. If you enable, send data on click, and ui\_control is et to selectable value 1, i.e. only one row selected at a time, the message resulting makes sense, msg.row is what ever row was clicked on.

However, the exact same message is set, if the row is deselected, i.e. no row is actually highlighted or otherwise selected. The message returned just reports the row of the click, no select or deselection state, it appears.

I would think this would be valuable feature to add, it does not somehow already exist? Maybe add to the message generated some boolean flag to know a selection, versus a deselection occurred?

Thinking I could keep a flow variable to track the selection state, but that seems a kludge in the sense that the ui-table should report selection/deselection somehow?

---

<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:** [12 January 2024 06:44 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/2 "2024-01-12T06:44:48Z")

</div>

Bump! No one really?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [13 January 2024 20:37 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/3 "2024-01-13T20:37:02Z")

</div>

How are you deselecting the row? If any row is selected all other rows are deselected.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 January 2024 12:09 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/4 "2024-01-14T12:09:19Z")

</div>

As the callbacks here [Tabulator | JavaScript Tables & Data Grids](https://tabulator.info/docs/4.7/callbacks#select) do not seem to function except `rowSelectionChange`, and that returns no data (must be something in the underlying ui-table code), It is a difficult thing to do.

Here is a hack that seems to work but is not fully tested.

```auto
[{"id":"07204902246bf46f","type":"ui_table","z":"d1395164b4eec73e","group":"51ce6aa1.620754","name":"Thermostats","order":1,"width":"20","height":"7","columns":[],"outputs":1,"cts":true,"x":390,"y":2940,"wires":[["35b9715a26dfec55"]]},{"id":"7c29aa761984f5ff","type":"change","z":"d1395164b4eec73e","name":"ui_control","rules":[{"t":"set","p":"ui_control","pt":"msg","to":"{\"tabulator\":{\"selectable\":1,\"rowSelectionChanged\":\"function(data, rows) {this.send({ui_control:'change'})}\"}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":2940,"wires":[["07204902246bf46f"]]},{"id":"35b9715a26dfec55","type":"delay","z":"d1395164b4eec73e","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":550,"y":2940,"wires":[["e8c4db900a2673a3"]]},{"id":"1f63f052afd35258","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload","v":"[{\"name\":\"MEQ0451495\",\"room\":\"Bathroom\",\"SET_TEMPERATURE-value\":22,\"ACTUAL_TEMPERATURE-value\":21.8,\"VALVE_STATE-value\":90,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":true,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875547\",\"room\":\"Living Room\",\"SET_TEMPERATURE-value\":12,\"ACTUAL_TEMPERATURE-value\":16.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":1},{\"name\":\"MEQ1875538\",\"room\":\"Living Room\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":19.5,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.6,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":2},{\"name\":\"MEQ0447462\",\"room\":\"Kitchen\",\"SET_TEMPERATURE-value\":17,\"ACTUAL_TEMPERATURE-value\":22.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":10,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":3},{\"name\":\"MEQ1875551\",\"room\":\"Office\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":20.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ0447425\",\"room\":\"Dining Room\",\"SET_TEMPERATURE-value\":19,\"ACTUAL_TEMPERATURE-value\":20.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875546\",\"room\":\"Dining Room\",\"SET_TEMPERATURE-value\":20,\"ACTUAL_TEMPERATURE-value\":18.8,\"VALVE_STATE-value\":99,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ0447483\",\"room\":\"Bedroom\",\"SET_TEMPERATURE-value\":17,\"ACTUAL_TEMPERATURE-value\":22.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875541\",\"room\":\"Child\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":20.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875552\",\"room\":\"Guest Room\",\"SET_TEMPERATURE-value\":20,\"ACTUAL_TEMPERATURE-value\":21.1,\"VALVE_STATE-value\":9,\"BATTERY_STATE-value\":2.8,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0}]","vt":"json"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"name\":\"MEQ0451495\",\"room\":\"Bathroom\",\"SET_TEMPERATURE-value\":22,\"ACTUAL_TEMPERATURE-value\":21.8,\"VALVE_STATE-value\":90,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":true,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875547\",\"room\":\"Living Room\",\"SET_TEMPERATURE-value\":12,\"ACTUAL_TEMPERATURE-value\":16.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":1},{\"name\":\"MEQ1875538\",\"room\":\"Living Room\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":19.5,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.6,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":2},{\"name\":\"MEQ0447462\",\"room\":\"Kitchen\",\"SET_TEMPERATURE-value\":17,\"ACTUAL_TEMPERATURE-value\":22.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":10,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":3},{\"name\":\"MEQ1875551\",\"room\":\"Office\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":20.2,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ0447425\",\"room\":\"Dining Room\",\"SET_TEMPERATURE-value\":19,\"ACTUAL_TEMPERATURE-value\":20.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875546\",\"room\":\"Dining Room\",\"SET_TEMPERATURE-value\":20,\"ACTUAL_TEMPERATURE-value\":18.8,\"VALVE_STATE-value\":99,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ0447483\",\"room\":\"Bedroom\",\"SET_TEMPERATURE-value\":17,\"ACTUAL_TEMPERATURE-value\":22.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875541\",\"room\":\"Child\",\"SET_TEMPERATURE-value\":18,\"ACTUAL_TEMPERATURE-value\":20.4,\"VALVE_STATE-value\":0,\"BATTERY_STATE-value\":2.7,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0},{\"name\":\"MEQ1875552\",\"room\":\"Guest Room\",\"SET_TEMPERATURE-value\":20,\"ACTUAL_TEMPERATURE-value\":21.1,\"VALVE_STATE-value\":9,\"BATTERY_STATE-value\":2.8,\"BOOST_STATE-value\":0,\"AUTO_MODE-value\":false,\"CONTROL_MODE-value\":0}]","payloadType":"json","x":110,"y":2940,"wires":[["7c29aa761984f5ff"]]},{"id":"e8c4db900a2673a3","type":"function","z":"d1395164b4eec73e","name":"function 149","func":"if(msg.ui_control == \"change\"){\n context.set(\"row_data\", {row: null, bool: false})\n}else{\n let row_data = context.get(\"row_data\") || {row:null, value: false};\n let old_row = row_data.row;\n let value = row_data.bool\n let new_row = msg.row;\n if(old_row === new_row){\n value = !value;\n }else{\n value = true\n }\n context.set(\"row_data\", {row: new_row, bool: value})\n msg.selected = value;\n return msg;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":3000,"wires":[["a43b46c3b5e3e69d"]]},{"id":"a43b46c3b5e3e69d","type":"debug","z":"d1395164b4eec73e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":3040,"wires":[]},{"id":"51ce6aa1.620754","type":"ui_group","name":"ui_control","tab":"3b08fac0.8f06b6","order":1,"disp":true,"width":"22","collapse":false},{"id":"3b08fac0.8f06b6","type":"ui_tab","name":"Home","icon":"track_changes","order":1,"disabled":false,"hidden":false}]

```

---

<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:** [14 January 2024 17:50 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/5 "2024-01-14T17:50:45Z")

</div>

@Buckskin, I have set the ui-table to allow only 1 row selected at a time. The sequence is, click on row, get message. click on same row again, I get another message (basically) identical. I tried using a flow variable to track the msg.row value, test of the same row or different row is clicked. Pseudo logic I think is right...

Table created, i.e. initialized with data, and no flow variable exist, thus no value in flow variable, so create flow variable and set to row value -1.

User clicks on any row (initially), and that row does not equal the flow variable, set flow variable to new row value, a new row event has occurred, so handle it.

So far so good...

User clicks same row and flow variable is equal that row, set flow variable to -1, then take appropriate action, i.e. a deselect of table row has occured.

---

<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:** [14 January 2024 17:51 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/6 "2024-01-14T17:51:14Z")

</div>

@E1cid, will give your suggestion a shot! Thanks.

---

<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:** [13 February 2024 17:51 UTC](https://discourse.nodered.org/t/how-to-trap-or-determine-when-a-row-is-deselected-in-ui-table/84293/7 "2024-02-13T17:51:45Z")

</div>

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