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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Reset Gallery Behaviour
Power Apps
Unanswered

Reset Gallery Behaviour

(0) ShareShare
ReportReport
Posted on by 716 Moderator

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:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    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

  • DCHammer Profile Picture
    716 Moderator on at

    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
    153,034 Most Valuable Professional on at

    @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
    716 Moderator on at

    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
    153,034 Most Valuable Professional on at

    @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
    716 Moderator on at

    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
    153,034 Most Valuable Professional on at

    @DCHammer ,

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

  • DCHammer Profile Picture
    716 Moderator on at

    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.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard