cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jbrit2020
Super User
Super User

Patch action resets Gallery selection

So...apparently this is normal behaviour from what I've gathered from previous posts, but is there any chance of stopping it?

 

When an item from my gallery is selected and then a button with a Patch is clicked, it resets the selected item on the gallery.

 

This is a bit annoying as the user might want to do further changes to the same item.

 

Any idea on how to stop this behaviour?

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
eka24
Super User
Super User

Try this:

On the OnSelect of a Button or Icon inside the Gallery (You can hide the icon) put:

  Set(MyselectedItem,ThisItem)

 

Then in the Default Property of the Gallery: MyselectedItem

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

View solution in original post

11 REPLIES 11
eka24
Super User
Super User

Try this:

On the OnSelect of a Button or Icon inside the Gallery (You can hide the icon) put:

  Set(MyselectedItem,ThisItem)

 

Then in the Default Property of the Gallery: MyselectedItem

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

View solution in original post

@eka24 that works, but then causes me another issue, it scrolls the selected item to the top of the gallery. 

 

Any idea how to make it steady?

@jbrit2020 
Where do you want the selected item to be located?

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Just want the gallery to stay steady and if the selected item is in the middle of the displayed gallery, just stay put without the gallery automatically scrolling to the top of the page.

eka24
Super User
Super User

Am afraid I dont think that can be done.

Assume you have 100 items in a Gallery, you select the 88th item.

The selected item has to to be pulled up because originally, the user scrolled down before the selection. Otherwise the 88th item selected would be hidden down in the Gallery.

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

RandyHayes
Super User
Super User

@jbrit2020 

Selected items in a Gallery will change if the Items property has any significant evaluations.

Normally if the Items property is just a datasource, the gallery will not change, but if you have a filter statement or some other functions in that and, whatever you are patching impacts that formula, then the gallery will refresh data.

 

There are several ways around this:

1) As @eka24 mentioned - set a snapshot variable to the record and use that in the default.  As you see, this has the side-effect of resetting the record position - quite annoying.

2) Create a snapshot of your Items list into a variable and use that as the Items property (yes, I said variable - there is no need for a collection but many use one for this method) - This works but the gallery data then will not change dynamically as is usually desired - AND, any reference to ThisItem will now be based on the snapshot in the variable (and would be for a collection as well).

3) This one involves some effort but completely resolves the issue - First create a snapshot variable of the ID's of the Items in the Gallery - Only ID's are needed.  So, your Items property will just be a single column table of ID's that you want to show.  Then, for any labels or other controls in the Gallery, you would, instead of referring to ThisItem.column, you would need to do a LookUp(datasource, ID=ThisItem.ID, columnName).  So, it gives a little more work on the controls in the Gallery, and it also has the side-effect that values in the Gallery can be slow to display and/or change a little oddly when loading.  But, Patching/Updating will not impact the list position.

You can balance this by, instead of just a table of ID's, a table of ID's and any value that will NOT be impacted by the filter formula.  i.e If Title, for example, would never be evaluated in the formula, then you can include that column and any other columns like it in your initial snapshot table - then do Lookups on any other columns that would be part of the impacted formula.

 

I hope that makes some sense.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes I'm going mental....eka24's solution was working for most of the afternoon albeit with the annoying gallery position movement, but now out of the blue, instead of doing that, it's resetting any selection all together and now just de-selects everything.....

 

I'm going to search for a new job

So, Here's an odd thing...I just revisited an old app of mine to check if I was experiencing the same issue there. 

 

And I found out that the issue is not quite the same. When I apply a filter to my gallery using a combobox, the selection stays put as I want it, but if I don't have any filter on that combobox, the selection goes away when I patch

RandyHayes
Super User
Super User

@jbrit2020 

Filter(NewJobs, Salary>1000000 && RequiredWorkHoursPerWeek=0 && StressLevel=0)

 

As I mentioned in the reply that I had, this is very common when you are impacting the underlying Items of the Gallery.  It will usually always refresh itself.  I would review over those 3 items I mentioned and see if one works best for you.  But, the bottom-line - if you impact the results of the Items formula with a patch (and I don't mean just a simple change of a value, but to a value that is used in any criteria in the filter) then the Gallery will refresh.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,745)