Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Nested gallery will not collapse when not selected (not visible)

(0) ShareShare
ReportReport
Posted on by 235

I feel like I'd solved this already.  I had an app, there was something fundamentally wrong with it as no patches of columns from the gallery would work.  I could patch a literal value, but was unable to patch any of the gallery fields which absolutely had data in them.

When I'd click a button on the page with the gallery to do the patch, if I examined any of the fields I was attempting to patch they were null within that gallery and I know this because I put them in a variable and they were null.  So again, it would patch a literal value like "Hello there" to say a single line text field but it would not patch txtInputNotes  which was the field name in the gallery.  Nor txtInputNotes.Text  nor txtInputNotes.Value.   I tried every way possible but it wouldn't text anything but a literal in quotes.

 

I cut it down so bare that I finally gave up and thought I'd have to build a new gallery.  duplicated the page, built new gallery from scratch (well it's a groupby situation so I built 2).   I don't know if I can patch yet, just trying to finish the gallery to the point I had it before.  Now this new gallery is not hiding the nested gallery items when the parent is not selected.  I'm trying EVERYTHING.  I checked a video to recall if I did something wrong and in the video the child gallery was hidden simply by putting an IsSelected in the Visible property.     Sadly this isn't working for me either.   I don't want to pound on this for days and days if there's something fundamentally wrong with this new set of galleries I'm creating.  And since I never give up, I will waste days and days until I finally just give up and try again.

 

ANY suggestions are welcome I'm at wits end and working on my vacation time.   very sad.

Categories:
  • Chris-D Profile Picture
    1,246 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    I'm not seeing this at all on my test. If it's only happening when you switch screens, maybe check the OnVisible and OnHidden of your screens. 

     

    Could the collection that captures your changes be a duplicate name from elsewhere in your app? 

  • AmyF Profile Picture
    235 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    @Chris-D    So I removed the extraneous code to refresh and recollect everything and it was working fine... yesterday.  Today I get on, open the app and the entire gallery of IDs filled up again on every/many onChange fields with the IDs.   I don't get why those onChange events are firing during load.   I will see if I can put in a limiter to only perform the onChange if there is a change in field value, like you suggest.  Still seems very weird that those would fire on loading the app.  Also, and this didn't seem to be happening yesterday, if I clear that data out using a button I've put in, when in Dev, if I move from screen to screen, that screen's galleries populate and those IDs are recollected and display.  I didn't notice that yesterday and I'd have thought that I would have.   Anyway, my search for an answer to this continues.   Do you have any other insights on that?

  • AmyF Profile Picture
    235 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    once again your words are causing me to question things.  As I developed this, I put in extra code at the bottom of the patch button's onSelect.  I wasn't seeing my changes and sometime after that, I was so I just replicated that as my "working" copy throughout my app (GAH!!!)  So, I removed it and boom.  That's not happening now.  Thanks again.

  • Verified answer
    Chris-D Profile Picture
    1,246 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    This doesn't happen with my demo. 

     

    Why are you collecting the data before the gallery? You should just be able to put whatever you're collecting in Gallery.Items? 

  • AmyF Profile Picture
    235 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    Oh that's good, we may have many solutions as we go...  This brings up my current problem (beyond this).  After I patch, the datasource is refreshed, I recollect it and the gallery reloads with the data I just patched.  That's great except after the patch, during the reload process, every OnChange action on every control in every gallery fires and fills up that table I was collecting (after I've already Clear'd it out.   So it just fills right up with IDs and older data that I've already patched and cleared out of that thing.   It's crazy.   I've read that this is a bug, but how can that be?  No one would use OnChange to collect the changes if it was so messy.   Are you aware of this error? I'm trying to come up with a workaround that would allow me to use the OnChange for this but so far, I'm at a loss (big surprise there)   😉

     

     

  • Chris-D Profile Picture
    1,246 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    Patch( Data, Collection) shouldn't touch every record. I've checked my demo data from the example I posted before and it has only modified the rows that were changed.

    ChrisD_0-1694608194058.png


    To tidy up your list above, use the OnChange code that I posted before. If the ID already exists in the table of changes then it's updated instead of adding a new value. I found it helps to avoid confusion and mistakes, to ensure your list of changes is compatible with your data source, you can define the new record like this:

    // Here, adding Penguins@ before the record ensures that the record is 
    // compatible with the Penguins data source
    Collect( GalleryChanges, Penguins@{
     ID: ThisItem.ID,
     Note: Self.Text
    })

     

    No need to start a new thread, you can mark more than one answer as the solution 🙂

  • AmyF Profile Picture
    235 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    Well again, sir, thanks.  I do have one more followup question, more of an algorithm one.  Originally one one of my other screens, I simply collected the IDs, then I did a distinct on them because I knew if it was in there that I just had to force a status of "Approved" or whatever.   

     

    Now, I've got 2 possible fields that may be updated.  So now I end up with a list of IDs and changes that look like this:

    cID      cStatus     cNotes  cTimestamp    (there will be more fields ultimately)  and the records look like this:

     2          Approved                                   9/12/2023 11:05:33

     2                          These are my notes    9/12/2023 11:05: 42

     2           <blank>                                     9/12/2023 11:05:47

     2          Waitlisted                                    9/12/2023 11:05:51         

    This series of changes shows a change to status from blank to Approved

    a change in notes from blank to "These are my notes"

    a change in Status from Approved to Blank   (maybe a mistake)

    a change in Status from blank to "Waitlisted"

    What I really want is the ending state of both of these fields prior to hitting the button that performs the patch.

     

    Can you suggest a scheme for collecting this information and refining it?   I didn't think this far since I was blocked with the other problem.  So I'm just wondering if you have any suggestions for a "best practice" for collecting this data and executing it?   I need to loop through it because the changes are relatively small and the data set is very large and wide and the Patch(myDataSource, myCollection)  is way too "expensive" and seems to touch every record in the datasource whether changed or not, but truly shouldn't and also when I tested this before... even though I was patching just a few things, each record had a new Modified date.

     

    Either I'm doing something wrong (what are the odds?) or that is the behavior and it really isn't a good choice for large data sets?   

    If you'd like me to start a new thread, I'm happy to.  wanna get you your kudos.   But any suggestions in that regard would be helpful   -- do you know of a source for "best practices" that might involve this?   

     

    I don't want to dry your well, so much beer IS available if needed    😄

  • Chris-D Profile Picture
    1,246 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    No problem, glad you got it working 🙂 

     

    ThisItem - inside a gallery, this is the record for that row. 

    ThisItem.Column - the value of the column for that row.

     

    Self - on a control is a reference to itself. 

    Self.Selected - on a control like a dropdown is the current selected item

    Self.Selected.Value - on a dropdown created from a list of single values is the value of that item

     

    Does that make sense? 

    YouTube? No thanks haha! 

  • AmyF Profile Picture
    235 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    Chris!!!   Let's make arrangements for beer!!!  Thank you for sticking with me.  I was attempting to collect ThisItem.Status.Selected.Value,  that didn't work but when I changed it to Self.Status.Selected.Value of course it didn't work either but when I finally landed on Self.Selected.Value it worked.   I still don't understand why I can get the row id using ThisItem  but need Self for the data .... is it that ThisItem refers to the row and Self refers to the cell itself?     This is the problem I've been having all along.  I need to understand this better but you sir, who did not give up on me, lead me to the answer even when I couldn't see it so #1 THANK YOU SO MUCH.  #2 You should make a video, I can tell by the thumbs up on my questions on youtube that it would get a lot of hits.  Anyway I'm accepting your last as the solution because you drilled it into my head such that i could translate it to my code....  eternally grateful and owe you BEER!!!

  • Verified answer
    Chris-D Profile Picture
    1,246 on at
    Re: Nested gallery will not collapse when not selected (not visible)

    Hi Amy, thanks for the reply I thought you might have given up 😉

     

    I'm aware of how GroupBy() works and am very familiar with nested data structures but thanks for the explanation.


    In my example above...

     

    Gallery1.Items:

     

    GroupBy(
     Sort(
     AddColumns( 
     Penguins,
     "CountDate", DateValue( $"{Coalesce(day, 1)}/{Coalesce(month, 1)}/{year}"),
     "CountDateText", $"{Left( Text( Coalesce(month, 1), "mmmm"), 3)}-{year}"
     ),
     CountDate, SortOrder.Descending
     ),
     "CountDateText",
     "Data"
    )

     

     

    Gallery2.Items (nested inside Gallery1) exactly as you say:

     

    ThisItem.Data

     

     

    InputNotes.OnChange inside Gallery2 (my text input control):

     

    // See if we already have a change record for this item
    If( IsBlank( LookUp( GalleryChanges, ID = ThisItem.ID)),
    
     // If we don't, create a record
     Collect( GalleryChanges, {
     ID: ThisItem.ID,
     Note: Self.Text
     }),
    
     // If a record exists, update it with this change
     Patch( GalleryChanges,
     LookUp( GalleryChanges, ID = ThisItem.ID), 
     {
     Note: Self.Text
     }
     );
    )

     

     

    This produces the list of changes displayed in my data table above. You should simply be able to patch from this as I said:

     

    Patch( DataSource, CollectionOfChanges);

     

     

    Just for fun, I added a button and did (almost) exactly this and hey presto, my list is patched. 

    ChrisD_0-1694520039398.png

    I would suggest that you can't find an example because you are looking for a 'GroupBy gallery' which isn't a thing. 

     

    Anyway, since I have provided a working example you can PM me to arrange the beers 😉 

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

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,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,026 Most Valuable Professional

Leaderboard