cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
nepowerappsuser
Level: Powered On

ForAll on Nested Gallery

I'm using a nested gallery as a bit of a hack to get something that looks like an editable datatable with dynamic columns (see screenshot). The outer gallery represents the rows and the inner gallery (which just has a textinput in the template to act as the cell), the columns. With some jiggery pokery to get something that looks like column headers, and as long as the number of columns (items in the inner gallery) don't become too wide for the outer gallery, creating horizontal scrollbars per row, it works ok.

 

I'm using the textinput onchange to patch a collection that keeps track of the data until i want to save back to the datasource.

 

The problem I have is that the onchange event changes focus of the selected 'cell', so when the user clicks or tabs into the next cell, the event fires on the previously selected input and moves focus away from where the user wants to be. Which creates a frustrating user experience.

 

The ways i've thought about resolving this:

 

  1. If PowerApps allowed programmatic control of focus, i could maybe re-set focus after the onchange event fired, but this isn't support functionality.
  2. Don't use the onchange event, and let the collection go stale. This would require a means of looping through the textinputs in the inner gallery to get their values. 

With option 2, I can't seem to get access to the AllItems of the inner gallery, it is always empty. I've tried a few different permutations of nested ForAll statements, etc. but even the simple example below returns a week number (expected) and blank value (not expected) for every row of the collection (outer gallery). 

 

ForAll(OuterGallery.AllItems,Collect(testcount,{week: lblWeek.Text, colcount: CountRows(InnerGallery.AllItems)}));

 

Any suggestions?

 

Thanks in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: ForAll on Nested Gallery

Hi @nepowerappsuser,

I have made a test on my side, and don't have the issue that you mentioned. The screenshot as below:2.JPG

 

3.JPG

4.JPGSet the OnSelect proeprty of the "Collect" button to following:

Clear(testcount);
ForAll(
    Gallery1.AllItems,
    Collect(
        testcount,
        {
            StudentName: StudentName,
            Count: CountRows(Gallery2.AllItems)
        }
    )
)

On your side, you should type:

Clear(testcount);
ForAll(
OuterGallery.AllItems,
Collect(
testcount,
{
week: lblWeek.Text,
colcount: CountRows(InnerGallery.AllItems)
}
)
)

Please consider take a try to add a Label control within your OuterGallery, set the Text property to following:

CountRows(InnerGallery.AllItems)

then check if the Label control shows proper value (rather than blank).

 

In addition, as an alternative solution, you could consider take a try to add a Label control (called "InnerGalleryCountLabel") within your OuterGallery, set the Text property to following:

CountRows(InnerGallery.AllItems)

then modify your ForAll formula as below:

Clear(testcount);
ForAll(
OuterGallery.AllItems,
Collect(
testcount,
{
week: lblWeek.Text,
colcount: InnerGalleryCountLabel.Text
}
)
)

If the issue still exists, please consider take a try to remove the InnerGallery from your OuterGallery, then re-add it again, try above formula I provided, check if the issue is solved.

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: ForAll on Nested Gallery

Hi @nepowerappsuser,

I have made a test on my side, and don't have the issue that you mentioned. The screenshot as below:2.JPG

 

3.JPG

4.JPGSet the OnSelect proeprty of the "Collect" button to following:

Clear(testcount);
ForAll(
    Gallery1.AllItems,
    Collect(
        testcount,
        {
            StudentName: StudentName,
            Count: CountRows(Gallery2.AllItems)
        }
    )
)

On your side, you should type:

Clear(testcount);
ForAll(
OuterGallery.AllItems,
Collect(
testcount,
{
week: lblWeek.Text,
colcount: CountRows(InnerGallery.AllItems)
}
)
)

Please consider take a try to add a Label control within your OuterGallery, set the Text property to following:

CountRows(InnerGallery.AllItems)

then check if the Label control shows proper value (rather than blank).

 

In addition, as an alternative solution, you could consider take a try to add a Label control (called "InnerGalleryCountLabel") within your OuterGallery, set the Text property to following:

CountRows(InnerGallery.AllItems)

then modify your ForAll formula as below:

Clear(testcount);
ForAll(
OuterGallery.AllItems,
Collect(
testcount,
{
week: lblWeek.Text,
colcount: InnerGalleryCountLabel.Text
}
)
)

If the issue still exists, please consider take a try to remove the InnerGallery from your OuterGallery, then re-add it again, try above formula I provided, check if the issue is solved.

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

nepowerappsuser
Level: Powered On

Re: ForAll on Nested Gallery

Kris,

 

Thank you very much for your response. I've now cracked it, but...

 

When I recreated your steps on a new screen all worked as expected, but initially I could not get my real version working despite deleting and recreating the inner gallery and various other tests.

 

After much experimentation, I discovered why your steps worked, but my original didn't. The label displaying the CountRows(InnerGallery.AllItems) is the key! I'm guessing this, or any other enumaeration of InnerGallery.AllItems,  forces PowerApps to evaluate the items of the inner items in the same context as my ForAll is executing, but without this, I get the same results as I initially reported where InnerGallery.AllItems is effectively null.

 

Is this a bug, or expected behaviour?

 

Thanks again

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 53 members 3,308 guests
Please welcome our newest community members: