cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WillyD44
Level 8

Resetting Gallery Selection Formula - Why does this work?

I read a thread on this PowerApps user forum that helped me acheive my desired end state...but I DON'T KNOW WHY IT WORKS and it's killing me. 🙂  

 

I want to set the value of a Gallery to not have any items in the gallery selected...in essence, show ALL gallery items.  This in turn affects how my table displays data as my table control is set to show only the row of data that corresponds to the Gallery selection.  But...what if the user says, "I don't want to look at a single record in the table any longer.  I want to see all table records."  At this point, I need to clear the Gallery.Selected value so that nothing is selected, which in turn will drive my table to show all records. 

 

A picture is worth a thousand words.  This sould tie things together.  

 

In the below image, the user selects Hull (Gallery1) in the Facility list.  Hull then shows in the Facility Details Table (Table Control whose data source is a SharePoint list).  

 

ResetSelectionButtonScenario1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

But now, the user wants to reset the selection in the Facility to list to NONE...or BLANK.  The user wants all the facilities to show.  So, the user clicks the Reset Selection button and sure enough, the selection in Gallery1.Selection goes to BLANK and he is able to see all table records now.   See below screenshot, then see my question below that. 

 

ResetSelectionButtonSyntax.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Last detail...Gallery1 (Facility list, far left column)...Gallery1's Default property is set to: ResetButton.

 

What I don't understand is why the OnSelect property formula has to be the way it is.  I would have thought it should have been like this:

 

OnSelect = UpdateContext({ResetButton:{}})

 

If I use the property formula above, the Reset Selection Button works one timeAfter that it does not work.  

 

 

Why does the property have to be set to what the screenshot above shows to work?  In the event the screenshot does not show the working property formula well, here it is:

 

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})

 

Hopefully someone can help.  It won't do me much good to have a formula stashed away with no understanding of how to use it, change it, improve it for different scenarios, etc. 

 

Bill

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Mike8
Level 10

Re: Resetting Gallery Selection Formula - Why does this work?

Hello,

OnSelect = UpdateContext({ResetButton:{}})
This works the first time because the default property of the gallery is set to an empty record ---> {}.
Before it wasn't an empty record and it changed to an empty record. 🙂
If you try to press it again, it will not work because the second time you set the ResetButton variable from {} to {}. So, it doesn't change. If the ResetButton doesn't change powerapps doesn't trigger the default property.

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})
This works every time because in the same expression, you set the ResetButton to a value (Gallery1.Selected) and then you set it to an empty record. So, the ResetButton changes and powerapps triggers the default property.

To sum up, this is how powerapps works. You need to change the variable in the default property in order to trigger and apply the default value on the gallery.

View solution in original post

5 REPLIES 5
Microsoft Employee

Re: Resetting Gallery Selection Formula - Why does this work?

I don't know which thread you're referencing to so it would be helpfull to also know how your ResetButton is set. Is it like this?

Gallery1.OnSelect=UpdateContext({ResetButton: Gallery1.Selected})

And then your second gallery uses it for filtering the content?

Highlighted
Mike8
Level 10

Re: Resetting Gallery Selection Formula - Why does this work?

Hello,

OnSelect = UpdateContext({ResetButton:{}})
This works the first time because the default property of the gallery is set to an empty record ---> {}.
Before it wasn't an empty record and it changed to an empty record. 🙂
If you try to press it again, it will not work because the second time you set the ResetButton variable from {} to {}. So, it doesn't change. If the ResetButton doesn't change powerapps doesn't trigger the default property.

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})
This works every time because in the same expression, you set the ResetButton to a value (Gallery1.Selected) and then you set it to an empty record. So, the ResetButton changes and powerapps triggers the default property.

To sum up, this is how powerapps works. You need to change the variable in the default property in order to trigger and apply the default value on the gallery.

View solution in original post

WillyD44
Level 8

Re: Resetting Gallery Selection Formula - Why does this work?

Mike8...brilliant!  Great, clear and detailed explanation.  Thank you for taking time to answer my question. 

 

Best regards,

Bill

RussW
Level: Powered On

Re: Resetting Gallery Selection Formula - Why does this work?

Hi,

Thanks for bringing this function up in the forums. 

May I suggest an alternative I've discovered that has less overhead?

I discovered it mainly out of your suggestion not quite working for my app's gallery.

 

Simply, I want to select a name from a gallery list and have this trigger the displaymode on a button from disabled to edit essentially not allowing the button to activate without first selecting a name from the list. In working through this, I found the below formulas work to deselect the name in the list and/or start with no name selected when you navigate to the screen.

 

Set the Gallery1.Default to {}        < an empty record

Set the ResetButton.OnSelect to Reset(Gallery1)        < resets the gallery to default

 

 

DeeTronSEAM
Level: Powered On

Re: Resetting Gallery Selection Formula - Why does this work?

Thanks, @WillyD44  !

 

Using the Reset(NameOfMyGallery) method (aka formula) WORKS.  This is surprising since (currently) PApps galleries do not have a Reset property.  But hey, I'll take it.  It sure is easier than using the default property of the gallery via a toggled context variable.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 349 members 6,107 guests
Please welcome our newest community members: