cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kudo Kingpin
Kudo Kingpin

Gallery Default property type/format?

Hi there,

I'm working on an on call roster app. Users will see who is rostered on call this week, as well as previous and future entries in the roster.

I want to implement this as a gallery. I want to use the Default property of the gallery to set the displayed gallery item. This is so that the initial scroll position of the gallery will be at today's on call duty, and the user can scroll up or down to see adjacent entries. The problem I've encountered is, I can't figure out how to set the value of the Default property.

The Gallery control properties documentation doesn't say which which type it uses, nor does it give an example situation using this property.

In fact, I wouldn't have even known this was the correct property to use, had it not been for this forum post - https://powerusers.microsoft.com/t5/PowerApps-Forum/Gallery-Scroll-to-a-Default-Item/m-p/4558/highli... . However, the method suggested in the post leaves the type and/or format of a Default property value opaque to the user.

How can I set the value of a gallery's Default property?
20 REPLIES 20

I have created an idea for the Reset property of galleries.  Please add your kudos to it, thanks.

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Add-a-Reset-property-to-galleries/idi-p/18128

I have edited the above post, now the button always resets the selection to the second default record in the Default property If statement.  @lifelongjourney does this resolve your need?

LifeLong,

 

I see what you are trying I think.  So the first record with todays date and your ID is what you want default to take you to, yes?

 

In that case, and this applys anytime a function takes an expression, you should be able to modify it as follows:

 

LookUp(roster_on_call, Date=Today() && ID=currentUserID)

 

the && above is a logical(boolean) AND which requires that both expressions result to true. This should take you to that record when you start the application. 

 

Meneghino is right though, once you manually select something, the default no longer works until you update it. Using a button would be a good way to do that, but you can basically use any event driven property of any control to perform it as well. 

 

Hope that works for ya!

@Meneghino and @TschoofBAHthanks for your responses, you've both moved further forward than I can get. @Meneghino, the second item in your "bearing in mind" list was:

2. When the app is started, the gallery will show the Default item and it will be selected

This is currently not happening. This is the most critical for me. if I can have a Today button that resets the gallery back to the default, that'd be great, but this relies on the Default property working in the first place, which it isn't for me (yet!).

 

Maybe it's because the data source (a SharePoint list) has Lookup columns? This is the spec of the used columns:

 

DataSource = 'On Call Roster', a SharePoint list

  • Begin (Date)
  • End (Date and Time)
  • On Call (Lookup to external list "On Call Staff" - Name (Single line of text))
  • On Call:Mobile (Lookup to external list "On Call Staff" - Mobile (Single line of text))
  • ID (built-in)

NB: I don't have access to the list settings, so I can't unify the column settings for Begin and End

 

Gallery control = galRoster

galRoster.Items = 'On Call Roster'

galRoster.Default = First(Filter('On Call Roster', DateDiff(Today(), DateValue(End, "en-US"), Days) > 0))

 

I also have a textbox control, lblCurrentRosterID, which displays the current ID, just to reassure me that I am getting the correct ID

lblCurrentRosterID = "CurrentRosterID: " & First(Filter('On Call Roster', DateDiff(Today(), DateValue(End; "en-US"), Days) > 0)).ID

 

If this is another Lookup support issue in PowerApps, will be very frustrated...

Hi @lifelongjourney thanks for being so specific with your questions.

 

There are a few reasons I can think of why the Default may not be working, so let's try a simple test.

 

What happens if you simply do this?

galRoster.Default = Last ('On Call Roster')

Does the app open up with the last item showing and selected? (instead of the first one showing and nothing being selected)

 

Also, just to make double sure all is working, I would have another text box with .Text = galRoster.Selected.ID

 

This should show blank on app startup if Default is not working as expected, otherwise it should show an ID (in our test the ID of the last item)

PS Also try this

 

Create a button with .OnSelect = UpdateContext({ResetVar = true}); UpdateContext({ResetVar = false})

 

Set galRoster.Default = If(ResetVar, First('On Call Roster'), Last('On Call Roster'))

 

See if the button manages to force selection of the last item.  Please let me know.

@Meneghino great suggestion for follow up.

 

I changed galRoster.Default to Last ('On Call Roster') and setup lblGallerySelectedID.Text = galRoster.Selected.ID as recommended.

 

The first one shows nothing being selected, and the textbox shows blank on app startup.

 

I liked your button idea, I had a slightly different take and created two buttons.

ButtonTrue.OnSelect = UpdateContext({ResetVar: true})

ButtonFalse.OnSelect = UpdateContext({ResetVar: false})

Before clicking either button, I would select a different entry, for example 17.

 

Both ButtonTrue and ButtonFalse behaved in the same way. If a button click changed the ResetVar from its previous value, the lblSelectedRosterID would be blank. I then select entry 17, and clicked the same button again. This of course did not change the ResetVar. lblSelectedRosterID stayed at 17. Same for the third and fourth clicks etc. Then if I click the other button, the loop starts again.

 

In other words, not even First('On Call Roster') is working, let alone Last().    😞

 

What else you got in mind?

Community Champion
Community Champion

Well, here is one suggestion to see if the issue is to do with data retrieval.
Create a button with OnSelect = ClearCollect(LocalRoster, 'On Call Roster')
Substitute LocalRoster for 'On Call Roster' in all the above gallery properties etc. and see what happens. You need to press the new button once to load the collection first, of course.
If this also does not work, I will come bck to it tomorrow and do some tests.

View solution in original post

OMG this worked! I've refactored my code back to my original functions and it's working! Thankyou @Meneghino!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,421)