cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SamPo
Power Participant
Power Participant

Issue with Default Gallery Item

Hi,

 

I have a data source called 'Tickets'
I have a gallery displaying all items and when I select an item I set a global variable called 'SelectedTicket'
On another page I display a filtered gallery of the same items and I want the default selected item of this gallery to be the 'SelectedTicket' from the previous page.

 

The Items for this gallery are:

Filter(Tickets,Contact=SelectedTicket.Contact)

The Default of this gallery is:

LookUp(Tickets,TicketNumber=SelectedTicket.TicketNumber)

From everything I know, this should work but the gallery just always displays the first item even if I do a manual 'reset' from a button.

 

Anyone have any ideas?

Thanks

Sam

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @SamPo ,

 

Now I got you. yes, it won't work when you apply a filter on datasource. Create a Collection with the datasource and filter on that collection, this works. But, please don't ask why (if it works) that is the fix I have seen for the same issue for on my requirement.

 

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

View solution in original post

12 REPLIES 12
eka24
Super User
Super User

What formula do you have for the variable.

Edited

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

KrishnaV
Super User
Super User

Hi @SamPo ,

 

I have implemented a sample with your scenario, see the below working model and formulas I have used:

Default gallery selection.gif

Formulas on the gallery:

Gallery Default: LookUp(colReported,ID=Dropdown11.Selected.ID)
Items: colReported // This is a collection
TemplateFill: If(ThisItem.IsSelected,RGBA(22, 220, 220, 5), RGBA(242, 242, 242, 5))

on the Edit Form:

Item: First(Filter(SampleList,ID=Gallery25.Selected.ID))


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
SamPo
Power Participant
Power Participant

@KrishnaV Thanks for the detailed response.

 

When I set the gallery to be just 'Tickets' then this works as expected. When I change the gallery items to be a filter of the data source then it stops working properly. I'm jumping between pages each time this variable is set, don't know if that has something to do with it though I don't see why it should matter.

 

@eka24 I'm just setting this variable from a previous gallery with the following code:

Set(SelectedTicket,LookUp(Tickets,TicketNumber=varTicketNumber))

I know this variable is working as I'm using it in other places and as I said above, this works when I set the gallery to be based just off the data source with no filter.

SamPo
Power Participant
Power Participant

Okay, I've found the pattern. It only works if the values of the gallery are updated.

As you can see from my formula I'm looking up a 'contact'. If the contact stays the same (and hence the gallery values stay the same) then the default selection does not update. If I select an item related to another contact (and hence the gallery values do update) then the default selection works.

 

I've tried adding a 'reset' command for the gallery and even put it on a button on the same page so I can manually force it but it doesn't work.

 

Any ideas?

I asked for the Variable because i think there should be an additional variable. I tested this:

  1. Set a Variable in Gallery1

        Set(SelectedTicket,Gallery1.Selected); Set(Selected1,Gallery1.Selected.TicketNumber)

  1. Filter in Gallery2

         Filter(Tickets,Contact = SelectedTicket.Contact)

  1. Default in Gallery2

        LookUp(LookUp, TicketNumber=Selected1)

 

     4. On the Template fill of Gallery2:

If(ThisItem.IsSelected,Green,RGBA(0, 0, 0, 0))

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

SamPo
Power Participant
Power Participant

@eka24 I tried changing the formula as you suggested but it produced the same result as I described above.

When the data in the gallery changes the default value updates correctly. When the data remains the same, it stays on the first value even if I reset the gallery control.

Hi @SamPo ,

 

Now I got you. yes, it won't work when you apply a filter on datasource. Create a Collection with the datasource and filter on that collection, this works. But, please don't ask why (if it works) that is the fix I have seen for the same issue for on my requirement.

 

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
SamPo
Power Participant
Power Participant

@KrishnaV  Yes that seems to be the case. I was trying to avoid going down the collection route. In theory this data source could go quite large, I could limit the amount of records shown but prefer not to.

 

I thought it would work on filtered data sources as according to the comment in the solution here by  @Mr-Dang-MSFT : https://powerusers.microsoft.com/t5/Building-Power-Apps/Set-Gallery-Default-based-on-Global-Variable...

 

"The formula above should work if the Gallery's items is spListCollection or some filter on it."

 

According to that statement it should work for filtered items but clearly this doesn't seem to be the case.

 

Thanks

Sam

Hi @SamPo ,

 

Yes, I have tried many many ways but I got the solution only by making it a collection. Please let me know if you see any challenge I am more than happy to help.


Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,145)