Power Apps Containers for Gallery Columns

If you use a lot of galleries in your Power Apps, you may have noticed that it can get tedious sometimes, lining things up and arranging controls, especially when you want your gallery to look more like a table.  Yes, there is a data table control, but it doesn’t have as much functionality and flexibility as a gallery.  In this post, I’ll show you how you can make your gallery responsive.  This means that as the screen size changes, the columns expand and contract, and stay even.  When using a container to achieve this, you’ll save time that you would have spent in arranging and adjusting all of those labels.

Here is what an app looks like when resized, by default, with Scale to fit turned ON.  Notice that the app stays in the same rectangular shape, no matter how you re-size the browser or screen, and it stays at the same dimensions.

power-apps-scale-to-fit

On the settings screen, in the display section, you can turn Scale to fit OFF.

powerapps-settings-display-scale

When that setting is turned OFF, the app’s controls will then have the ability to be responsive as you change the size of the screen by either adjusting the size of the browser window, or opening the app on different devices such as mobile phones or tablets.  When the app is responsive, I like my gallery columns to be able to have a variable width as the app size changes, but unfortunately by default they will be cut off, like this:

powerapps-screen-columns-cut-off

In this post, I’m going to show you a solution to that problem, and a solution to the tedious nature of creating and lining up many labels to create the look of columns in a gallery.  This is a way to make your whole gallery responsive using containers.  I’ll be inserting a container inside of the gallery for the labels AND on top for the “column headers”.

1.  With your cursor inside of your gallery, click on the Insert button on the far left, and choose Horizontal container.

powerapps-insert-horizontal-container-gallery

2.  Give the container a useful name.  I’ll rename mine ctnProjectRow.  Your container will just be in a random spot in your gallery for now, that’s fine.

3.  If you are starting from scratch from a brand new gallery with this container in it, just select the new container, and choose Label from the insert tab, to put each new label inside of the container.  If you are starting from an existing gallery with labels in it, you can cut each label from that gallery row, and paste each one inside of the container, like this.  I’ve cut and pasted two of my seven so far:

powerapps-project-gallery-container-inside

(Note that you may see an error when you cut and paste labels. into the container.  The error will be coming from the OnSelect property.  If your OnSelect says “Select(Parent)”, you can just change it to false.  We’ll address this later)

4.  For this container’s properties, the first thing is to set its X=0, Y=0, and Width= Parent.Width      As you can see in this screenshot, I used Parent.Width – 5  this is because my gallery has some padding, and I didn’t want it hanging off the edge.  Also, I have an icon in my gallery on the far right.  I brought it forward, so that it is in front of the new container.

powerapps-container-parent-width

5.  Now that the first container is situated in the gallery, here are the next settings to set up:

container settings:

Direction: horizontal

Justify: space between

Align: start

Gap: 0

Overflow (both): hide

Wrap: off

powerapps-container-properties-overflow-direction

6.  Next,  select the labels in the container, and set them up as follows:

height: 40
align in container: set by container: start
flexible width: on
minimum width: 30
vertical align: middle
overflow: hidden
auto height: off

7.  If you have a column that needs to be wider than other columns, you can change the Fill portions property.  For example, my “Description” column needs to be wider.  Since I have 7 columns, the fill portion value for description by default is 1 of 7.  I edit it and change it to a 2, which automatically then shows as 2 of 8.  You can do this for multiple columns, in order to adjust their width in relation to the whole gallery’s width.

8.  Now it’s time to do this same thing with the labels that go at the top of your gallery.  Create a new horizontal container, insert it towards the top of your screen.  I’m naming mine ctnColumnHeaders.

9.  Repeat step 3.  This time of course you’re not inside of the gallery, but you’re inserting or copying/pasting all of the labels to represent each column.

10.  Drag the container to a spot right above your gallery.  Set the following properties in this second container:

X: 0
Width: Parent.Width
Direction: horizontal
Justify: space between
Align: start
Gap: 0
Overflow (both): hide
Wrap: off

11.  Select all of the labels in this second container, and set them up as follows:

height: 40
align in container: set by container: start
flexible width: on
minimum width: 30
vertical align: middle
overflow: hidden
auto height: off

Set up the fill portions for these column headers in the same way that you set them up inside of the gallery in the first container, so that everything lines up.  For example, I set this description column to take up 2 fill portions in the container in the gallery, so I did the same thing for that column header label in the container on top of the gallery.

powerapps-container-fill-portions

12. If you need to have buttons in your gallery row, as you can see I have a couple of them in the screenshot above, just be sure and move them to be layered above the container in the gallery, like this.  Notice that the icons are on top of the ctnProjectRow container:

powerapps-layer-container-icons

13. When placing the icons or buttons, or whatever controls you’re adding to your gallery on top of the container, be sure and align them relative to the right side of the screen.  For example, when I take a look at the X axis property of the far right icon, IcoCopyRecord, it has a value of 1293.  Change it to:

Parent.Width – Self.Width – 15

powerapps-icon-location

I subtracted an extra 15 pixels, so that there will be some space between the right side of the icon, and the right edge of the gallery.

Here is the end result.  When I maximize the app to fill my desktop, and then when I make the browser narrower:

powerapps-wide-containers

powerapps-narrower-containers

Compare those to the third screenshot at the top of this post, and how the gallery gets cut off when the screen is narrower.

16 comments

  • Hi Laura
    I am having an issue inserting a horizontal container into a gallery. I click inside the gallery and then the pencil icon in the top left hand corner and click insert -> Horizontal container. The container is inserted outside of the gallery not inside it.

    Regards

    Nigel

    • Try inserting a label in the gallery, and then click to select the label. That way you’re forcing it to make sure your cursor is inside the callery before inserting the container.

  • Hi Laura,
    Why we cant have edit buttons inside container like other components ?
    >>12. If you need to have buttons in your gallery row, as you can see I have a couple of them in the screenshot above, just be sure and move them to be layered above the container in the gallery, like this. Notice that the icons are on top of the ctnProjectRow container:

    • You can put buttons in the container, sure. If you did that, though, it would be huge, and would be the same size as all of the other columns, and it would take up its own entire column.

  • Hi!
    When adding a container in to the gallery with multiple labels icons etc., the Galleries TemplateFill property isn’t showing anymore. So I can’t color in the item on IsSelected. Any suggestions?

  • Hi Laura, it seems you can only add a layout container to a gallery in regular canvas apps and to a gallery in a canvas apps for teams. Are you aware of any workarounds or related tips?

    • I’m sorry I don’t understand what the problem or issue is. In the example, a canvas app is what I was using. I wouldn’t be surprised if this doesn’t exist in a model-driven app (I’ve never used them).

  • Hi Laura,

    How do you access the textboxes and other controls inside the Horizontal Container?

    I was using a Patch with a direct txt_control1.Text but all records get same value…
    Is this a bug? Or is it because I am not using the context correctly?

    This is my code:
    ForAll(
    myGallery.AllItems As _item,
    Patch(
    ‘My Table’,
    {
    ‘Quantity’: txt_Quantity.Text
    }

    Usually this would have to be: _item.txt_Quantity.Text but since I have the Container I cannot seem to be able to access the controls inside the container.

    Any tricks here?

    • I don’t usually do the gallery’s all items, I usually point to a collection or some specific data source.

    • Yes, you can’t access the items if you place them into containers, as they are not at the root of the gallery. This trick is good for static galleries, but if you use them to patch information, you’ll have to go the usual way of aligning manually every item 🙁

  • Any chance you could show your entire tree view for this project. I’m not sure if the containers are supposed to be siblings within the Gallery or if one container should be outside of the Gallery, and the Project Row inside of the Gallery

  • Hi how to use save button in gallery..i am trying to save the set of 5x questions in powerapps..created 5x questions in gallery dont know how to save it..

  • I step 3 you mentioned “(Note that you may see an error when you cut and paste labels. into the container. The error will be coming from the OnSelect property. If your OnSelect says “Select(Parent)”, you can just change it to false. We’ll address this later)”. How is this addressed so that the functionality stays the same (select record when clicking controls within a container)?

Leave a Reply