Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Reset Gallery Behaviour

(0) ShareShare
ReportReport
Posted on by 714 Super User 2025 Season 1

I read a bunch of threads here and this doesn't seem to be addressed.

 

I have a Gallery (AllChecklists) and for the purposes of this discussion, the other pages and forms don't even matter. All of the behaviour I'm concerned about happens right in the Gallery.

 

Page Properties:

OnVisible

 

UpdateContext({SortOrder: If(IsBlank(SortOrder), "Ascending", SortOrder)});
UpdateContext({CompFilter: If(IsBlank(CompFilter), "Yes", CompFilter)});
UpdateContext({ScrollPosition: 0})

 

Gallery [AllChecklists] Properties: 

Items:

 

Sort(
 Filter('IBC Checklists', Completed = If(CompFilter = "No", true, false)
),
 Created,
 SortOrder
)

 

OnSelect:

 

UpdateContext({positionVal: ThisItem})

 

Sorting Icon Properties:

OnSelect:

 

If(
 SortOrder = "Ascending",
 UpdateContext({SortOrder: "Descending"}),
 UpdateContext({SortOrder: "Ascending"})
);
UpdateContext({positionVal: Blank()});
Reset(AllChecklists);
Select(AllChecklists, 1);

 

 

So it works...MOST OF THE TIME.

 

Here is what happens:

If I change the sort direction using the Icon when I have selected ANY record on the first 'page' in the gallery everything works perfectly. If however, I choose a record that is 'near' the end of the Gallery but not AT the end, it will decide to Reset the Gallery and Select the Last record instead of the first record.

 

I think the answer is changing the Select(AllChecklists, 1) function but I don't know why or how. Why does "1" arbitrarily change?

 

Categories:
  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Reset Gallery Behaviour

    Man...nothing I've tried has worked. Every 'solution' I can find doesn't work.

     

    There seems to be a lack of consistency in the Gallery behaviour itself so I've tried forcing the situation with Refresh and specific record choices in the gallery but that doesn't work either.

    The Gallery is populated with:

    Sort(
     Filter('IBC Checklists', Completed = If(CompFilter = "No", true, false)
    ),
     Created,
     SortedOrder
    )

    This is the code behind the icon changing SortedOrder in the Gallery:

    UpdateContext(
     {
     SortedOrder: 
     If(
     SortedOrder = SortOrder.Ascending,
     SortOrder.Descending,
     SortOrder.Ascending
     ),
     positionVal: Blank()
     }
    );
    
    Reset(AllChecklists);

    positionval is a variable for making deep linking work instead of using the ThisItem property directly on later pages.

    I've put this into the Default for the Gallery with fingers crossed but no luck:

    If(
     SortedOrder = SortOrder.Ascending,
     Last(AllChecklists.AllItems),
     First(AllChecklists.AllItems)
    )

    And that even seems to work. It resolves to the correct record in both cases.

     

    But the Gallery doesn't scroll to the correct position.

  • WarrenBelz Profile Picture
    146,620 Most Valuable Professional on at
    Re: Reset Gallery Behaviour

    @DCHammer ,

    Normally to do that, you would need to set the Default of the gallery to the record you want there.

  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Reset Gallery Behaviour

    So what I want is that when the page loads initially or any time the sort order is modified, that the gallery scrolls to the top of the gallery and has no chosen record at all.

    I'm not sure I can get that but I'd be willing to live with the gallery scrolling to the top and the first record visible in the gallery selected.

    The latter being what I was trying to accomplish with: Select(AllChecklists, 1)

  • WarrenBelz Profile Picture
    146,620 Most Valuable Professional on at
    Re: Reset Gallery Behaviour

    @DCHammer ,

    OK - I get that, but what do you expect the gallery to look like when the user lands on the page - do you expect the target record to be at the top - if so you need to look at the Default of the gallery.

  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Reset Gallery Behaviour

    I did go back to that previous logic.

    The deep linking is intended to allow a user to click a link/button on the Checklist Items page which will use Outlook and Sendto to start an email with a url that will lead the user directly to this specific Checklist Items page. 

  • WarrenBelz Profile Picture
    146,620 Most Valuable Professional on at
    Re: Reset Gallery Behaviour

    @DCHammer ,

    You can probably go back to your code on that one - I changed it later with some brackets but I think shorting it still may not work.

    I am not however understanding your "deep link" comment - are you expecting the Gallery to have that item at the top ?

  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Reset Gallery Behaviour

    positionVal is to indicate Gallery.Selected because I want to be able to deep link.

    So the underlying page, Checklist Items, which is where the user would be 'deep linked' to, uses positionVal to determine which record.

     

    I've made all of your suggested changes which I thoroughly appreciate and I'll test just as soon as I figure out the syntax error that seems to exist in your one code snippet.

     

    Sort(
     Filter(
     'IBC Checklists', 
     Completed = CompFilter = "No"
     ),
     Created,
     SortedOrder
    )
  • WarrenBelz Profile Picture
    146,620 Most Valuable Professional on at
    Re: Reset Gallery Behaviour

    Hi @DCHammer ,

    I will give you a couple of suggestions to make this a bit cleaner
    Page OnVisible

    UpdateContext(
     {
     SortedOrder: Coalesce(SortOrder, SortOrder.Ascending), 
     CompFilter: Coalesce(CompFilter, "Yes"),
     ScrollPosition: 0
     }
    )

    Gallery Items

    Sort(
     Filter(
     'IBC Checklists', 
     Completed = (CompFilter = "No")
     ),
     Created,
     SortedOrder
    )

    Sorting icon OnSelect

    OnSelect:
    UpdateContext(
     {
     SortedOrder: 
     If(
     SortedOrder = SortOrder.Ascending,
     SortOrder.Descending,
     SortOrder.Ascending
     ),
     positionVal: Blank()
     }
    )

    Note first that SortOrder is not a good name for a Variable.
    But my main question is how exactly you are using positionVal  and ScrollPosition

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,620 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,962 Most Valuable Professional

Leaderboard