cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sal
Level: Powered On

Dynamically changing Gallery source

How can I change the Gallery source based on the Dropdown choice selection? I like to display dropdown with two values ["1", "2"], on the second screen I like to display the items based on the dropdown selected, if user select 1, Gallery Control source should change to 1, if user select 2, Gallery source should change to 2. Right now I'm able to do If(Dropdown.Selected.Value = "1", 1, 2). But thats not the dynamic way to do that. I want to only pass Dropdown.Selected.Value or a varriable but it's not taking that as a source. Source 1,2 are the SharePoint List. I have already connected to those lists and able to access them from PowerApps.

 

Thanks,

-Salman

 

 

7 REPLIES 7
JRaasumaa
Level 10

Re: Dynamically changing Gallery source


@Sal wrote:

How can I change the Gallery source based on the Dropdown choice selection? I like to display dropdown with two values ["1", "2"], on the second screen I like to display the items based on the dropdown selected, if user select 1, Gallery Control source should change to 1, if user select 2, Gallery source should change to 2. Right now I'm able to do If(Dropdown.Selected.Value = "1", 1, 2). But thats not the dynamic way to do that. I want to only pass Dropdown.Selected.Value or a varriable but it's not taking that as a source. Source 1,2 are the SharePoint List. I have already connected to those lists and able to access them from PowerApps.

 

Thanks,

-Salman

 

 


 

If you have 2 sources you can change the Gallery Item propertiy to simply look at the dropdown and then display the data source. Keep in mind the sources need to have identical column layouts.

 

For example you can do:

 

 

If (Dropdown1.Selected.Value = "1",

Source1,

Source2)

Or even better,

 

 

Switch(Dropdown1.Selected.Value,

"1", Source1,

"2", Source2,

Source3)

 

Even better, collect an "All" at the start of your dropdown to show both sources combined (if you can load all this into a collection or pull all from 1 source)

 

Then have the dropdown have a 1, 2 to filter the large collection of items.

 

Hope that helps a bit!

 

Highlighted
Sal
Level: Powered On

Re: Dynamically changing Gallery source

Thanks , But I don't want to update the dropdown list everytime, dropdown list reading choices from SP list as well.

 

if I use this

 

Switch(Dropdown1.Selected.Value,

"1", Source1,

"2", Source2,

Source3)

Than I have to reopen the app and add Source4, Source5 in that. Can I have that pass dynamically so I dont need to open the app to update that?

 

Thanks.

-Sal

JRaasumaa
Level 10

Re: Dynamically changing Gallery source

Is your data all in one collection either in Sharepoint or SQL/Excel etc?

 

 

Sal
Level: Powered On

Re: Dynamically changing Gallery source

dropdown choices (choices are the different list names in the sharepoint site) are in SharePoint list column. on selection of the dropdown it pass that selection to gallery control to display items from that list. if i put a switch or if statment that hard code the choice value than I have to open the powerapp all the time to modify the logic to accept more cases in the switch statment.

JRaasumaa
Level 10

Re: Dynamically changing Gallery source


@Sal wrote:

dropdown choices (choices are the different list names in the sharepoint site) are in SharePoint list column. on selection of the dropdown it pass that selection to gallery control to display items from that list. if i put a switch or if statment that hard code the choice value than I have to open the powerapp all the time to modify the logic to accept more cases in the switch statment.


 

I understand now I think, you want a DropDown of SharePoint names (that updates from another sharepoint list) to use as your gallery Item property source. My understanding is this is not possible due to how PowerApps looks at the Table for your Items property of the Gallery.

 

Because PowerApps evaluates a DropDown selected item as a "value" (text/numeric type) instead of a "Table" source I don't believe this is going to work.

 

Possibly someone has figured out a workaround to using a DropDown selection as the actual Table for a Gallery but I've only ever had success filtering static table(s) in a gallery.

 

 

Sal
Level: Powered On

Re: Dynamically changing Gallery source

Thanks, I'm using Switch(listName, "List1", List1, "List2", List2)) for now, but the downside of that is on every screen where I use Gallery Control to display data from that list I have to use this.

magikbus
Level: Powered On

Re: Dynamically changing Gallery source

To do this use the OnSelect option in your dropdown and set it something like this. I have not tested this exact if statement for your example, so this is off the top of my head

OnSelect = If(drpSelector.Selected.Value="1",Set(varDataBase, DatabaseName1), Set(varDataBase, DatabaseName2))

 

This will create a table variable with the database stored in it. This is the part where I am not sure if this is a good thing or a bad thing, as I can see this variable getting VERY large if the database has too many records. So not sure if this is a viable solution, as I have only done this on a test list with limited data.

 

Then you set all the references to your database in the Gallery to use the variable instead of the Database name.

 

I have done this with forms too, but found that the Attachments fields gets a bit wonky and will not display the attachments the way it should. I'm still playing with it. This of course does not really help you with a dynamic list of databases. As you said you will still have to open the App and edit it to add new databases.

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: 105 members 5,446 guests
Please welcome our newest community members: