πΉ Using Galleries for Data Display in Power Apps β A Complete Guide
π Introduction
A Gallery in Power Apps is a control used to display and interact with multiple records from a data source. It allows users to scroll through data, select items, and apply filters, sorting, and search functions.
β Why Use Galleries?
- π Displays multiple records in a structured way.
- π Supports filtering, sorting, and searching.
- π± Works dynamically with different data sources (SharePoint, SQL, Dataverse, etc.).
- π¨ Customizable layout and design.
πΉ Step 1: Adding a Gallery Control
1οΈβ£ Open Power Apps Studio.
2οΈβ£ Click Insert β Gallery.
3οΈβ£ Choose a gallery type:
- Vertical (default, for lists).
- Horizontal (for carousels).
- Flexible Height (for items with variable text sizes).
4οΈβ£ Connect to a data source: - Select the gallery.
- Click Properties β Items.
- Set
Items = DataSourceName
(e.g.,Items = Employees
).
π Now, your gallery is connected and displays data!
πΉ Step 2: Customizing the Gallery Layout
1οΈβ£ Select the Gallery β Click Edit Layout.
2οΈβ£ Choose a pre-defined layout (Title, Title & Subtitle, Image & Title, etc.).
3οΈβ£ Add or remove controls (Labels, Images, Icons) as needed.
4οΈβ£ Bind controls to data fields:
- Select a Label inside the gallery.
- Set Text = ThisItem.ColumnName (e.g.,
Text = ThisItem.Name
).
π Now, each record displays correctly inside the gallery!
πΉ Step 3: Formatting and Styling the Gallery
β Changing Colors & Fonts
- Select Gallery β Format using the Properties pane.
- Customize Fill, Border, Font, Color, Padding, etc..
- Example:
TemplateFill = If(ThisItem.IsSelected, RGBA(0, 120, 215, 0.5), White)
β Adjusting Gallery Size
- Set the Width and Height dynamically:
Width = Parent.Width Height = Screen.Height * 0.6
π This ensures the gallery fits the screen dynamically!
πΉ Step 4: Adding Search & Filter to the Gallery
β Adding a Search Box
1οΈβ£ Insert a Text Input (txtSearch
).
2οΈβ£ Modify the galleryβs Items
property:
Filter(Employees, StartsWith(Name, txtSearch.Text))
π Now, users can search for records dynamically!
β Adding a Dropdown Filter
1οΈβ£ Insert a Dropdown (ddlDepartment
).
2οΈβ£ Set its Items
property:
Distinct(Employees, Department)
3οΈβ£ Modify the galleryβs Items
property:
Filter(Employees, Department = ddlDepartment.Selected.Value)
π Now, users can filter records by department!
πΉ Step 5: Sorting the Gallery Data
1οΈβ£ Insert a Sort Icon (icoSort
).
2οΈβ£ Create a Sort Order Variable in OnSelect
:
UpdateContext({sortOrder: If(sortOrder="Ascending", "Descending", "Ascending")})
3οΈβ£ Modify the galleryβs Items
property:
Sort(Employees, Name, If(sortOrder="Ascending", Ascending, Descending))
π Now, clicking the icon toggles sorting order!
πΉ Step 6: Displaying Images in the Gallery
1οΈβ£ Add an Image Control inside the gallery.
2οΈβ£ Set its Image
property:
ThisItem.Photo
π Now, each record displays its associated image!
πΉ Step 7: Handling Item Selection
1οΈβ£ Add a Label outside the gallery (lblSelectedName
).
2οΈβ£ Set its Text
property:
"Selected: " & Gallery1.Selected.Name
π Now, clicking an item updates the label with the selected recordβs name!
πΉ Step 8: Adding Navigation from the Gallery
1οΈβ£ Insert a Button inside the gallery (btnViewDetails
).
2οΈβ£ Set its OnSelect
property:
Navigate(DetailsScreen, ScreenTransition.Fade, {selectedItem: ThisItem})
3οΈβ£ On the Details Screen, set a Label:
Text = selectedItem.Name
π Now, clicking the button opens a details screen for the selected item!
πΉ Step 9: Optimizing Performance for Large Datasets
β Use Delegable Functions:
- Use Filter(), Sort(), and Search() with SharePoint, SQL, Dataverse.
- Avoid First(), Last(), CountRows() on large datasets.
β
Enable Pagination for Large Data:
1οΈβ£ Add Next and Previous buttons.
2οΈβ£ Use collections to load data in chunks:
ClearCollect(PageData, Filter(Employees, ID > currentPage * 100 && ID <= (currentPage + 1) * 100))
π This improves performance when handling large datasets!
πΉ Step 10: Testing and Deploying the Gallery
β Test on Different Devices
- Preview (
F5
) and resize the app window. - Use Power Apps Mobile to check layout.
β Publish the App
- Click File β Save & Publish.
π Now, your gallery is fully functional and ready for users!
πΉ Conclusion
A well-designed Gallery in Power Apps enhances data visibility, user interaction, and app performance.
π‘ Key Takeaways:
β
Use dynamic properties for responsive design.
β
Add search, filters, and sorting for better usability.
β
Optimize performance using delegation and pagination.
β
Allow navigation from the gallery for detailed views.
π Now, your Power Apps gallery is ready to display data efficiently!