web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : wUFmALgX2uFcxWyiFUqjfX
Power Apps - Building Power Apps
Unanswered

Setting Focus in a Gallery

Like (0) ShareShare
ReportReport
Posted on 7 Dec 2021 16:12:31 by
I have a horizontal gallery of cards of events sorted by date. I would have, for example, a years worth of events from January to December; the items sorted in order by date.
 
If the current date were June 15, is there a way to navigate to the gallery and have the gallery set the focus on the item closest the date of June 15 and still retain their order.  I'd like the current date, whatever that is, to show in about the center of my screen so you don't have to scroll to the closest date. 
 
Below is an illustration that I hope helps. Anyone know how I should think about this?
 
Thanks in advance! Cindy
 
CindyZ_0-1638893466879.jpeg

 

I have the same question (0)
  • DCHammer Profile Picture
    714 Moderator on 30 Apr 2024 at 22:08:58
    Re: Setting Focus in a Gallery

    I know this is months old but this allowed me to figure out how to set the focus on a gallery item. It's kind of embarrassing that it took me this long to figure out since it's just the default property of the gallery itself. Why I never considered that you could focus on a specific record inside the gallery when it loads we'll never know. But now I know and since I already have/had a variable holding the ID of the record which is used throughout the app, it was incredibly simple.

     

    Thank you so very much.

  • aadhawan Profile Picture
    111 on 11 Aug 2023 at 18:40:58
    Re: Setting Focus in a Gallery

    Hey @Liam_Chapman ,

    Thank You for your post, it helped me understand how to use this reset function for building logic when an item is not available in my collection, prior to saving, it need to redirect the user to the question:

    Save Formula:

     Reset(FlexibleGallery);
     UpdateContext(
     {
     varFocusNumber: LookUp(
     colAudit,
     SelectedChoice = ""
     ).QuestionNumber
     }
     );
     Reset(FlexibleGallery);

    Default Formula:

    LookUp(colAudit, QuestionNumber = varFocusNumber)

     

    Thanks

  • Liam_Chapman Profile Picture
    187 on 07 Dec 2021 at 16:49:04
    Re: Setting Focus in a Gallery

    Hi @CindyZ ,

    If my understanding of what you are trying to achieve is correct, you could make use of the default property on the gallery.

    As a really simplified example I created a gallery which has a collection made up of the numbers 1 to 10.

    I then (as an example) made use of two buttons, one to move the gallery to number 1 and another to move the gallery to number 10.

    Each button updates a context variable which in turn is referenced in the galleries default property, they also RESET the gallery which causes the shift in focus.

    Default property of gallery:

    LiamChapman_0-1638895324828.png


    On Select of 'Go to 1' button:

    LiamChapman_1-1638895352349.png


    OnSelect of 'Go to 10' button:

    LiamChapman_2-1638895382976.png

    So as an example when 'Go to 10' is selected:

    LiamChapman_3-1638895419750.png


    All you would need to do is change the default item to be based on the current date, with a lookup of your items.

    I hope that helps in some way?

    Thanks,

    Liam



  • LiamChapman Profile Picture
    2 on 07 Dec 2021 at 16:44:35
    Re: Setting Focus in a Gallery

    [Removed]

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 917 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 387 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 334 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading started
Loading complete