cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
mr-dang
Level 10

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
PowerApps Staff murali
PowerApps Staff

Re: Gallery: Scroll to a Default Item

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
PowerApps Staff murali
PowerApps Staff

Re: Gallery: Scroll to a Default Item

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
Level 10

Re: Gallery: Scroll to a Default Item

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
PowerApps Staff murali
PowerApps Staff

Re: Gallery: Scroll to a Default Item

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
Level 10

Re: Gallery: Scroll to a Default Item

Confirmed. Problem solved.

 

Thank you.

Microsoft Employee
@8bitclassroom
Meneghino
Level 10

Re: Gallery: Scroll to a Default Item

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
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 (Last 30 Days)
Users online (5,987)