cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

How have nested gallery items access parent item properties

I have a gallery based on a ParentCollection where each item contains a ChildCollection (added with AddColumns) shown in a subgallery. ParentCollection has a column "Expand" with value set to false to start.
In the parent gallery item I want to hit an "expand" icon that changes the "Expand" property of the parent item and also behavior of the child gallery items.

F.e. I would like to have a label on the childitems with height set to (pseudo syntax)
If(Parent(ThisItem).Expand;60;40)

What syntax would I use?

 

Also when populating the collections I might also add a column expand to the childitems and when hitting the icon on the parent gallery item I might set all childitems to expand:true
When I try this using
ForAll(ThisItem.ChildCollection;{Expand : !Expand}) or
ForAll(ThisItem.ChildCollection;{Expand : true})
Nothing happens. Syntax and names are ok since I get no errors. But nothing happens. Renaming the expand column of the childitems to assure disambiguation ..  no difference.
How would I syntax that approach?


1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: How have nested gallery items access parent item properties

@HansHeintz 

Okay, so translating this from the sample app I gave you to what you have...

Somewhere in your app you have this formula on an OnSelect action (in mine it was the Load Data button):

ClearCollect(
    KennelDieren8;
    AddColumns(KennelDieren9;
      "Events"; 
         AddColumns(Filter(DierEvent;
                    DocaDierId=dier_id &&
                   (EventtypeId=3 || PlanStatus=0)
                    );
               "rProduct"; Produkt;    
               "EventExpand"; false
                     );
      "DocaDierNr";dier_id;
      "Expand";false                             
   )
)

 

I would change that to the following (as you don't need the EventExpand field in the sub table:

ClearCollect(
    KennelDieren8;
    AddColumns(KennelDieren9;
      "Events"; 
         AddColumns(Filter(DierEvent;
                    DocaDierId=dier_id &&
                   (EventtypeId=3 || PlanStatus=0)
                    );
               "rProduct"; Produkt;    
                     );
      "DocaDierNr";dier_id;
      "Expand";false                             
   )
)

 

 

The Gallery (the outermost) of your app would have this as its Items property (in mine it was on Gallery1):

KennelDieren8

 Your Inner/nested gallery would have a formula on the Items property like this:

AddColumns(ThisItem.Events; "Expanded"; ThisItem.Expand)

Your Icon for expand or colapse would have this in the OnSelect action:

UpdateIf(KennelDieren8; DocaDierNr=ThisItem.DocaDierNr, {Expand:!Expand})

Your Nested gallery will now have a ThisItem.Expand that will change based on the user click of the expand/collapse button.

This should all work for you.

 

Now, to expand (no pun intended) on the statements that you made...

A collection is a "snapshot" in time.  Just like a variable.  If you want to change it, you have a couple of options available.  BUT, when you start doing sub items (i.e. sub tables), you have more steps to go through. 

The advantage of the AddColumns is that it creates a calculated column in your Collection.  So, if you change something about the primary columns, the calculation will reoccur - without you having to re-collect (i.e. take another snapshot).

So, if we can use that mechanism to alter the values, then it is easy.

Otherwise, we have to redo the sub table and update/patch that column in the primary table.  Its a lot of hasle - add columns with a calculated is a breeze.

You would have to do something like this - Do a ForAll or UpdateIf and then use the output of that to update/patch the original table.  Again, a lot of hassle.

 

In the example above, you are using the outermost Expand column to pass the calculated column to the child.  You are doing this on the Items property of the nested gallery.  This will reevaluate whenever there is a change to it.  So...you don't need to do anything else, just let PowerApps do its thing.

 

I hope that is clear for you...If not, just let me know and I can provide more detail.

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

5 REPLIES 5
Highlighted
Super User III
Super User III

Re: How have nested gallery items access parent item properties

@HansHeintz 

So, the issue in the ForAll is that you are actually not doing anything in it...

What you might envision as actually setting the Expand property in the collection is not what is going on.  What it is doing is returning a table of records with an Expand field based on the expand property of your existing collection - that will not do anything for you (especially since you are not assigning it to anything).

In PowerApps, you can't alter values in that way.  The approach is to have your controls change their behavior based on the data.

So, in this case, you need to pass the Expand property of the parent to the child as part of the records. 

This can easily be done with AddColumns(ThisItem.childItems, "Expanded", ThisItem.Expand)

Now every record in the sub gallery will have the parent expand property.  When you change the parent Expand property (through your icon), the sub gallery items will have the proper value of the Expand.

 

Kind of hard to explain, so I've attached a quick sample app to this post.  Download it to your computer, then open PowerApps and either create a blank app or open an existing one.  Then once in the design, go to File->Open->Browse and choose the file you downloaded.

It's a simple Gallery with sub gallery.  The parent has an expand icon and the child gallery "Reacts" to the expand condition.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
Helper V
Helper V

Re: How have nested gallery items access parent item properties

Mmm not entirely clear to me yet.

Underneath is the exact code where a collection is added as a column for each item of an existing collection as part of the onselect code of a button.

I cannot place your code in there because clearcollect does not recognize "thisitem".
If I put your code
AddColumns(ThisItem.childItems, "Expanded", ThisItem.Expand)
or in my case AddColumns(ThisItem.Events, "EventExpand", ThisItem.Expand)
in the onselect code of the expand icon at the most the childitems of thisitem know this column but in practice the column "Expanded" does not compute anywhere.

Also I do not know why it would be impossible to change the values for a column in the childitems, be it as I tried before or by some patch construction or by 
UpdateIf(ThisItem.Events;true;{EventExpand:true})
which does not work either.

 

 

;;ClearCollect(
               KennelDieren8            
               ;AddColumns(KennelDieren9
                          ;"Events";AddColumns(
                                                Filter(
                                                                DierEvent
                                                                ;DocaDierId=dier_id And ((EventtypeId=3) Or (PlanStatus=0))
                                                        )
                                                ;"rProduct";Produkt    
                                               ;"EventExpand";false
                                               )         
                          ;"DocaDierNr";dier_id 
                          ;"Expand";false                             
                           )
)

 

 

Highlighted
Super User III
Super User III

Re: How have nested gallery items access parent item properties

@HansHeintz 

Okay, so translating this from the sample app I gave you to what you have...

Somewhere in your app you have this formula on an OnSelect action (in mine it was the Load Data button):

ClearCollect(
    KennelDieren8;
    AddColumns(KennelDieren9;
      "Events"; 
         AddColumns(Filter(DierEvent;
                    DocaDierId=dier_id &&
                   (EventtypeId=3 || PlanStatus=0)
                    );
               "rProduct"; Produkt;    
               "EventExpand"; false
                     );
      "DocaDierNr";dier_id;
      "Expand";false                             
   )
)

 

I would change that to the following (as you don't need the EventExpand field in the sub table:

ClearCollect(
    KennelDieren8;
    AddColumns(KennelDieren9;
      "Events"; 
         AddColumns(Filter(DierEvent;
                    DocaDierId=dier_id &&
                   (EventtypeId=3 || PlanStatus=0)
                    );
               "rProduct"; Produkt;    
                     );
      "DocaDierNr";dier_id;
      "Expand";false                             
   )
)

 

 

The Gallery (the outermost) of your app would have this as its Items property (in mine it was on Gallery1):

KennelDieren8

 Your Inner/nested gallery would have a formula on the Items property like this:

AddColumns(ThisItem.Events; "Expanded"; ThisItem.Expand)

Your Icon for expand or colapse would have this in the OnSelect action:

UpdateIf(KennelDieren8; DocaDierNr=ThisItem.DocaDierNr, {Expand:!Expand})

Your Nested gallery will now have a ThisItem.Expand that will change based on the user click of the expand/collapse button.

This should all work for you.

 

Now, to expand (no pun intended) on the statements that you made...

A collection is a "snapshot" in time.  Just like a variable.  If you want to change it, you have a couple of options available.  BUT, when you start doing sub items (i.e. sub tables), you have more steps to go through. 

The advantage of the AddColumns is that it creates a calculated column in your Collection.  So, if you change something about the primary columns, the calculation will reoccur - without you having to re-collect (i.e. take another snapshot).

So, if we can use that mechanism to alter the values, then it is easy.

Otherwise, we have to redo the sub table and update/patch that column in the primary table.  Its a lot of hasle - add columns with a calculated is a breeze.

You would have to do something like this - Do a ForAll or UpdateIf and then use the output of that to update/patch the original table.  Again, a lot of hassle.

 

In the example above, you are using the outermost Expand column to pass the calculated column to the child.  You are doing this on the Items property of the nested gallery.  This will reevaluate whenever there is a change to it.  So...you don't need to do anything else, just let PowerApps do its thing.

 

I hope that is clear for you...If not, just let me know and I can provide more detail.

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Helper V
Helper V

Re: How have nested gallery items access parent item properties

Thnx! That worked for me

BTW to set the collaps column of the parent item I CAN do (in the onselect of an icon on the parent item)

UpdateIf(KennelDieren;true;{Expand : false})
;;Patch(KennelDieren;ThisItem;{Expand : !Expand})

 

Highlighted
Super User III
Super User III

Re: How have nested gallery items access parent item properties

@HansHeintz 

Good deal!

Yes, your formula will result in all of the other currently expanded sections to collapse (not expand) and the one you are on (ThisItem) to be expanded.  Although the !Expand in the formula is ambiguous as the only real value at that point would be true, since you, in the previous line of the formula, had already set them all to false.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,039)