SOLVED. Gridview unselect item/ toggle it on then off with two clicks?

I’m using grid view to show a list of devices from which I want to pick more than one. This is linked to Node red using mqtt.
I get from node red a list of devices that includes all the possibles with ticks against those selected.

Inside the HR mqtt plug in i create an array for gridview that shows up as a column of devices with a tick icon against those included. If I click on any row, the new value for selected is sent to node red. Node red toggles that device on the included list, updates the master list and sends it back again. This works fine as long as I don’t click the same row more than once.

What doesn;t work is if I change my mind in HR and click the same device twice (toggle it ON, oops toggle it OFF again.) The selection hasn’t changed so no info is sent to node red. I have tried every option I can think of in property setting etc but cannot get this step to work correctly.

It seems the second and subsequent click on a device row in gridview is not being actioned. I have to click on another row in between the ON/OFF clicks on the same device.

Is there a way of getting round this?

Clicking items 2x will not reset the selection. If you’d like the option to click the same item multiple consecutive times you’ll need to clear the current selection first. What you can do is, whatever variable is bound to the SelectedValue, clear it in your plugin after you handle it. After you are finished processing the 1st click in your plugin, write a different value to that same variable in the plugin. You can set it to a value that isn’t in your item list if you want to clear all selections.

I must be getting something wrong as this doesn’t work. I have tried many ways around the issue doing more or less what you suggest. I even tried with a totally new attribute just in case.

My gridview selection is bound to EarlyStartRepeat.outLinks.

I click on an item in gridview.

onChangeRequest() works correctly giving me attribute ‘outLinks’ with the Id value of the item clicked as the payload. I send that on to node red which toggles the item on/off.

Node red sends back the info for the list with the selection updated. This is collected by onPoll and used to rebuild the arrays for gridview. All works marvellously except the item I clicked on is still highlighted.

Writing a new value to EarlyStartRepeat.outLinks either in the plugin or as an action on a button has no effect on the selected item highlight. It does however result in node red toggling that item - as expected.

Monitoring the attribute EarlyStartRepeat.outLinks by label shows it only changes by my direct actions but NOT when clicking on an item in gridview.

I think… The gridview selected variable is not accessible outside of gridview itself - but could be wrong

Help!

Thanks
Andy

Take clicking out of the equation for the time being. The GridView will update the selection automatically based on its Binding. I don’t think your plugin is updating the outLinks variable. Your attempt to place a Label by it’s side was a good step to help troubleshoot the issue. That actually confirms my suspicion.

“onChangeRequest” is a REQUEST to change a variable value. It doesn’t actually change the value. If you want to change the value, you need to write the new value to the device attribute. Look at the example plugin here, it does exactly that. You can update it immediately in onChangeRequest like that example or in onPoll. Either will work, but you are responsible for actually updating the device object

Bill. Thanks for being patient. I have got there in the end. It was all a problem between the keyboard and the screen.

The main thing I wasn’t doing was setting the bound gridview selection attribute to valueA in the onRequest() function. I then needed to change the value again to valueB in the onPoll(0 function when I received the updated values from node red.

As follows:

  1. Gridview binding for selected value path is EarlyStartRepeat.outLinks. There are about 12 items in the list with ids ranging from 55-65
  1. onRequest() sees a call for attribute “outLinks” with a value of 55-66. It sets device[“outLinks”] to some nonsense value - say 1000 but publishes the real value to node red via MQTT
  1. onPoll() gets the updated “outLinks” back from node red and uses it to populate the array used by gridview. It then sets “outLinks” to something out of range but different to 1000. the gridview control correctly updates and no longer has an item selected. BINGO

Missing out any of the steps to change the attribute value resulted in no visible change on the gridview - or a very delayed change. I think this understanding gap may be behind another of the problems I posted. will check this next.
Thanks.