cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mr-dang
Community Champion
Community Champion

Gallery: Scroll to a Default Item

Gallery1 holds some table data, but only shows the n column. Its purpose is to use wrapcount to show lots of items with basic information. 

 

 

Gallery1.Items=
Table( {n: 1, data1: "C", data2: "d"}, {n: 2, data1: "A", data2: "o"}, {n: 3, data1: "T", data2: "g"} )

 

You need to click Button1, which is an item in Gallery1, to see more information in Gallery2.

 

 

Button1.OnSelect=
UpdateContext({ShowGallery2: true})

Gallery2.Visible=
ShowGallery2

 

 

 

Gallery2 holds the same data, but shows only one entry at a time in a "fullscreen" view. So you will see n, data1, and data2. Nothing is filtered--the template is just so big that the others are not shown.

 

If I tap Button1 for the second entry,

{n: 2, data1: "A", data2: "o"}

Gallery2 will appear, but it starts at the beginning of the table. 

 

To get it to start at the nth entry, I did a little trick with Gallery2.

 

Gallery2.Items=
Sort(
AddColumns(Gallery1.AllItems,"Reorder",
If(n<Gallery1.Selected,n, Max(Gallery1.AllItems,n)-Abs(n-Gallery1.Selected.n)), (n-Gallery1.Selected.n),
Reorder)

 I added a column that recalculated the n number, and then sorted the gallery based on that. 

 

It works, but there are some limitations.

 

  1. The Gallery does not "loop." Galleries don't normally loop anyway. What I mean is that with the recalculated column, you will start with the desired item, but you can only go forwards--you can't conveniently go backward.
  2. If Gallery1 has more Sort functions, the recalculated column will not apply, since it is solely based on n.

    Gallery1.Items=
    Sort(Table( {n: 1, data1: "C", data2: "d"}, {n: 2, data1: "A", data2: "o"}, {n: 3, data1: "T", data2: "g"} ),data1)

    So if you sorted the table by the data1 column, then attempted to do the recalculated column, you would not achieve the sorted order.
  3. The Default property of the Gallery only affects what is selected. It does not seem to affect what is viewed by default.

 

So here's my question: is there a way to get Gallery2 to start at the selected item and still maintain the order of Gallery1?

Microsoft Employee
@8bitclassroom
1 ACCEPTED SOLUTION

Accepted Solutions

Gallery1 and Gallery2 should point to the same Items. This can be the same datasource, context variable etc. One way I achieved this is by setting OnVisible of Screen1 to be ClearCollect(Table, 
{num: 1},
{num: 2},
{num: 3},
{num: 4},
{num: 5}
)

 

Gallery1.Items = Table

Gallery2.Items = Table

 

Once I did this, it worked for me.

View solution in original post

5 REPLIES 5
murali
Power Apps
Power Apps

Hello - Gallery has a "Default" property which helps you set the default selection. Normally "Default" is empty meaning the selection is on the first item. You could do the following to achieve the effect you want.

 

On the button you mentioned below where you set 

UpdateContext({ShowGallery2: true})

 

do the following in addition

 

UpdateContext({ShowGallery2: true, Gallery1Selection: ThisItem})

 

Set Gallery2.Default =Gallery1Selection

 

Let us know if this helps.

 

Murali

mr-dang
Community Champion
Community Champion

Hi murali,

I had previously used the method you mentioned and tested it again. It seems that the Default property is not working in that case. Here is a quick mockup:

 

https://drive.google.com/open?id=0B0iHNZhZKR6YSHhPSWxDS1RLeTQ

Microsoft Employee
@8bitclassroom

Gallery1 and Gallery2 should point to the same Items. This can be the same datasource, context variable etc. One way I achieved this is by setting OnVisible of Screen1 to be ClearCollect(Table, 
{num: 1},
{num: 2},
{num: 3},
{num: 4},
{num: 5}
)

 

Gallery1.Items = Table

Gallery2.Items = Table

 

Once I did this, it worked for me.

View solution in original post

mr-dang
Community Champion
Community Champion

Confirmed. Problem solved.

 

Thank you.

Microsoft Employee
@8bitclassroom
Meneghino
Community Champion
Community Champion

I have created an idea for the Reset property of galleries.  Please add your kudos to it, thanks.

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Add-a-Reset-property-to-galleries/idi-p/18128

This solves the issue of resetting to the default item

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (3,045)