cancel
Showing results for 
Search instead for 
Did you mean: 

Add a Reset property to galleries

There is no Reset property to galleries that when toggled will reset the selection to the Default item.

This is strange since Reset is present for example in text inputs and other controls that also have a Default property.

Please add the Reset property to galleries.

Status: Completed

The reset functionality has been added to the Gallery control.  To reset a gallery, simply call Reset(GalleryInstanceName)

 

Note that this will reset the gallery to its initial state, but will not recursively reset all the children of gallery.

Comments
Power Automate Staff
Status changed to: Need Info

Galleries display all items in the items property by default unless a filter or search is applied on top of that. Removing the search or filter would reset the gallery.

 

Could you please clarify business scenario that would also need a gallery reset property?

 

Thank you for your clarifications in advance. @FilipK to comment further.

Audrie

Level 10

Here's a situation where you would want to reset a gallery to a default item:

https://powerusers.microsoft.com/t5/PowerApps-Forum/Reset-Gallery-Selected-value-and-passing-values-...

Microsoft

Another relevant scenario:

 

I am using a gallery as a "dropdown" alternative for large collections that require search & sort before selecting. Lets call it a selector.

When I click a selector that is currently blank, the gallery Default should be to the first item

When I click a selector that has a value, the gallery should show the current value selected.

eg. Default should reset to LookUp(MyCollection,id=selectedId). 

When I pass in the selectedId context variable for a blank selector, this lookup should also work fine for the default.

 

I have a form that has several different country fields. 

Because the list of countries is so long, I've opted to have each country "selector" be a textbox and a button. 

FormScreen.OnVisible=

If(
newForm, UpdateContext({passedID:"",getCountry:0,country1var:"",country2var:""}),
getCountry=1, UpdateContext({country1var:passedID,getCountry:0}),
getCountry=2, UpdateContext({country2var:passedID,getCountry:0}) )

Country1Text.Text=LookUp(Countries,id=country1var).name

Country1Button.OnSelect=

   UpdateContext({getCountry:1});

   Navigate(CountryScreen,Cover,{currentCountry:country1var})

Country2Text.Text=LookUp(Countries,id=country2var).name

Country2Button.OnSelect=

   UpdateContext({getCountry:2});

   Navigate(CountryScreen,Cover,{currentCountry:country2var})

 

So pressing the button on a country selector sends you to CountryScreen which has a gallery of Countries local collection, and passes in the currently selected countryid for that selector.

 

On the countries gallery page, I've set

BrowseGallery.Default=LookUp(Countries,id=currentCountry)

there's a transparent button overlaying the gallery item.

GalleryButton.OnSelect=Navigate(Form,Uncover,{passedID:BrowseGallery.Selected.id})

 

Thus, selecting a country passes back the id of that country to the Form and it assigns it correctly via the logic in the FormScreen.OnVisible. The selector behavior itself works as intended, but the gallery never selects the correct item.

 

Another forum post said the default will refresh if it has been changed, so I tried:
CountryScreen.OnVisible=UpdateContext({resetVar:false});UpdateContext({resetVar:true})

BrowseGallery.Default=If(resetVar,LookUp(....),LookUp(...))

 

Now I'm getting this strange behavior:

The first time I select a blank country selector (Country1), the CountryGallery appears as expected with the first (blank) item selected. If I select a non-blank value, like Austria, then Country1 is populated with Austria.

Next I click Country2 (still blank). When I arrive at the gallery screen, Austria is still selected. I choose a different country, like France. Now Country2 is populated with France.

If I click on the Country1 selector, now I go to the gallery and the blank value is selected!

 

Behavior patterns:

Select1=blank>>GallerySelection=blank,choose valueX>>Select2=blank>>GalSelect=valueX

Select1=blank>>GalSel=blank,choose valX>>Select1=valX>>GalSel=blank

Select1=valX>>GalSel=blank,choose valX>>Select1=valX>>GalSel=blank

Power Automate Staff
Status changed to: Under Review
 
Anonymous
Not applicable

Another scenario, I have a gallery pointing to a SharePoint list. Within the form for the items in this gallery is another gallery, a child list. I have a filter on this child gallery to show items based on the ID of BrowseGallery1.Selected.ID.

 

This works fine when viewing existing items, however, when I create a new item, the child gallery remains populated based on the previously selected item from the gallery. Being able to reset the "selected" property of the Browse gallery would solve this.

Power Automate Staff

@FilipK to comment on status 

PowerApps Staff

Are you expecting the reset on a gallery to change the ‘Selected’ template to the one defined in ‘Default’ input property?

 

You can achieve this today by having some formula like “If(x, First(CustomGallerySample), Last(CustomGallerySample))” on the gallery’s default property. Notice that it doesn’t reset all the controls, it changes the selected template in the gallery.

Level 10

Hi @FilipK, yes, that is what we are trying to achieve.

 

I am not sure that I understand your suggestion.  Let's say that the gallery has MyItems as the Items property and the Default property is LookUp(MyItems, ID = MyContextVariable)

 

Now, what does your suggestion look like?  Assume that the value of the context variable is an integer defined when first navigating to the screen and is not modified afterwards.

PowerApps Staff

If Gallery.Items = MyItems and Gallery.Default = LookUp(MyItems, ID = MyContextVariable), then when the gallery is loaded, the selected Item in the gallery will be the one where ID = MyContextVariable. It has to do with selection. Lets say MyContextVariable= 100 and assuming ID has values ranging from 0 through 500, usuaggly gallery displays the first few items in the app when it loads, bug since you have set the default here, it will automatically scroll to the 100th item and displays when it loads. That item will be the selectedItem.

Level 10

I have discovered another reason why this is important. Galleries whose Items are based on a collection will not revert to a Default until the collection is created.

 

For instance, if opening an app for the first time, Gallery1 has no items yet. The OnStart property of the app will then Collect() items and then Gallery1 will have items. Thereafter, the Gallery will not revert to the Default record in edit mode. In cloud mode, the gallery inconsistently reverts to the Default record--I'm still testing out why it does for some and not others.