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?
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.
Normally to do that, you would need to set the Default of the gallery to the record you want there.
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)
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.
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.
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 ?
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
)
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
WarrenBelz
146,620
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,962
Most Valuable Professional