Skip to main content
Microsoft logo
Power Apps
    • AI Builder
    • Automate processes
    • Azure + Power Apps
    • Build apps
    • Connect data
    • Pages
    • Take a guided tour
  • Pricing
    • Overview
    • Become a Partner
    • Find a Partner
    • Find partner offers
    • Partner GTM Resources
    • Blog
    • Customer stories
    • Developer Plan
    • Documentation
    • For IT Leaders
    • Roadmap
    • Self-paced learning
    • Webinars
    • App development topics
    • Overview
    • Issues
    • Give feedback
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • User groups
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Power Apps Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power Apps
    • Building Power Apps
    • Microsoft Dataverse
    • AI Builder
    • Power Apps Governance and Administering
    • Power Apps Pro Dev & ISV
    • Power Apps Portals
    • Connector Development
    • Power Query
    • GCC, GCCH, DoD - Federal App Makers (FAM)
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Community Blog
    • Power Apps Community Blog
    • Galleries
    • Community Connections & How-To Videos
    • Community App Samples
    • Webinars and Video Gallery
    • Canvas Apps Components Samples
    • Kid Zone
    • Emergency Response Gallery
    • Events
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Community Engagement
    • Community Calls Conversations
    • Experimental
    • Error Handling
    • Power Apps Experimental Features
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Power Apps Community
    • Galleries
    • Canvas Apps Components Samples
    • Custom ‘Gallery Pagination’ Component for Canvas A...

    Custom ‘Gallery Pagination’ Component for Canvas App

    10-24-2020 00:24 AM

    ShriramP
    Advocate II
    2819 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    ShriramP
    ShriramP Advocate II
    Advocate II
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Custom ‘Gallery Pagination’ Component for Canvas App

    ‎10-24-2020 12:24 AM

    PowerApps – Custom ‘Gallery Pagination’ Component

     

    Now in PowerApps, we can build our custom PowerApps Reusable Components which can be reused in many of our PowerApps applications. This is yet in preview mode.

     
     

    We had a custom requirement to have a pagination to PowerApps Gallery control. Current Gallery control in PowerApps supports up-down scroll like navigation. But there is no support available for going to the first page or last page or to the next or previous page, like we usually have in general real-world web applications.

     

    So, in order to achieve this, I have built a reusable PowerApps component called “Gallery Pagination”.

     

    GalleryPagination.jpg

     

    This component can be resized based on our need and can be used in Canvas Apps having Phone or Tablet layout.

    This is like Version 1.0 of “Gallery Pagination” component. I would maybe soon come up with new version having maybe support of Collection object and “possibility to jump to exact page” feature. Currently there is no support of Collection object in PowerApps Component.

     

    Just download and use it (with some supporting actions on Gallery and Parent Screen controls) like mentioned in the steps below.

     

    Below steps might look plenty but believe me it takes very less time to implement all these steps.

    Before you begin, make sure you have access to valid O365 tenant (trial or licensed). You would need One SharePoint Site and Valid PowerApps license.

     

    So, let’s get started!

     

    Steps 1: Create a sample Demo List in any test SharePoint site and add some dummy items. To see the real ‘Gallery Pagination’ Component usage in PowerApps, add at least 15-20 entries.

     

    1_1.jpg

    Image 1

     

    Step 2: Open PowerApps https://web.powerapps.com/ and create a new SharePoint connection like explained here

     

    2.1: Click Connections > Click “New Connection”

     

    2_1.jpg

    Image 2.1

     

    Step 2.2: Select “Connect directly(cloud-services)” > Click “Create” Button

     

    2_2.jpg

    Image 2.2

     

    Step 2.3: On SharePoint row, click “+” icon to create a new connection

     

    2_3.jpg

    Image 2.3

     

    Step 2.4: New SharePoint connection is now created

     

    2_4_2.jpg

    Image 2.4

     

    Step 3: Create a new Canvas app and add SharePoint connection

     

    Step 3.1: In “New app”, Select Canvas. It will open a new tab in browser.

     

    3_1.jpg

    Image 3.1

     

    Step 3.2: In new browser tab, select “Phone layout” (If you want, you can use Tablet layout as well).

     

    3_2.jpg

    Image 3.2

     

    Step 3.3: In new Canvas app, Open Data Sources from left navigation

     

    Image 3.3

     

    Step 3.4: Select SharePoint Connection created in Step 2

     

    3_4_1.jpg

    Image 3.4

     

    Step 3.5: Select SharePoint Site

     

    3_5_1.jpg

    Image 3.5

     

    Step 3.6: Select SharePoint List

     

    3_6_1.jpg

    Image 3.6

     

     

    Step 4: Add and Configure Gallery Control

     

    Step 4.1: Add Gallery Control to Canvas App

     

    4_1.jpg

    Image 4.1

     

    Step 4.2: Configure Data source and Layout as shown in image

     

    4_2.jpg

    Image 4.2

     

    Step 5: Save Canvas App

     

    5_1.jpg

    Image 5

     

    Step 6: Add “Gallery Pagination” Component to PowerApps environment

     

    Step 6.1: In Canvas App, Click File > Open > Browse

     

    6_1.jpg

    Image 6.1

     

    Step 6.2: Select “Gallery Pagination.msapp” from Downloads folder (which we downloaded earlier)

     

    6_2.jpg

    Image 6.2

     

    Step 6.3: This will close our canvas app and will open new App where Component will be visible in Components section.

     

    6_3.jpg

    Image 6.3

     

    Step 6.4: Save Component

     

    6_4.jpg

    Image 6.4

     

    Step 6.5: You can now see that Component is added successfully in your PowerApps environment. Close this component browser session now.

     

     

    6_5.jpg

    Image 6.5

     

    Step 7: Now open canvas app for adding and using component

     

    Step 7.1: Open Canvas App in Edit mode

     

    7_1.jpg

    Image 7.1

     

    Step 7.2: Click “+” icon in left navigation menu and in the Insert panel at the bottom select “Get more components”

     

     

    7_2.jpg

    Image 7.2

     

    Step 7.3: Select “Gallery Pagination” component and Import from the Import Panel

     

    7_3_1.jpg

    Image 7.3

     

    Step 7.4: Now “Gallery Pagination” component should be visible under Library components

     

    7_4.jpg

    Image 7.4

     

    Step 7.5: Add the component to Canvas app

     

    7_5.jpg

    Image 7.5

     

    Step 7.6 Adjust it according to screen size so that all “Gallery Pagination” controls appear correctly

     

     

    Image 7.6

     

    Step 8: Configure Canvas App Screen

     

    Add below snippet in OnVisible event of Canvas App screen.

    MySPCollection is a new collection where records from DemoList will be stored.

    InTotalItemsCount, InGalleryHeight, InGalleryTemplateHeight and varReset are input variables to Component control.

    Gallery1 is the name of gallery control added on screen.

    Important to note here is that Component Paging will be based on Gallery height and Gallery template height. Hence, we need to pass it to Pagination control.

     

    ClearCollect(MySPCollection, SortByColumns(DemoList, "Modified", SortOrder.Descending));

    Set(InTotalItemsCount,CountRows(MySPCollection));

    Set(InGalleryHeight, Gallery1.Height);

    Set(InGalleryTemplateHeight, Gallery1.TemplateHeight);

    Set(varReset, GUID());

     

    8.jpg

    Image 8

     

    Step 9: Configure Component Input Parameters

    Assign variables used in Step 8 to the component as shown in image below.

    You may also update few other input parameters if you wish or just let them have the default values.

     

     

    9.jpg

    Image 9

     

    Details of Component input parameters:

    Input Parameter

    (* are mandatory)

    Input Values / Default Values

    Description

    InTotalItemsCount (*)

    InTotalItemsCount

    Total Items Count

    InGalleryHeight (*)

    InGalleryHeight

    Gallery Height

    InGalleryTemplateHeight (*)

    InGalleryTemplateHeight

    Gallery Template Height

    ResetComponent (*)

    varReset

    To initialize component values based on reset event

    InFirstPageControlToolTip

    “Go To First Page”

    Tooltip of First Page Control

    InPreviousPageControlToolTip

    “Go To Previous Page”

    Tooltip of Previous Page Control

    InNextPageControlToolTip

    “Go To Next Page”

    Tooltip of Next Page Control

    InLastPageControlToolTip

    “Go To Last Page”

    Tooltip of Last Page Control

    InControlColor

    RGBA(0, 18, 107, 1)

    Color to set for component controls

     

    Step 10: Configure Gallery Control Based on Component’s Output Parameters

     

    Configure Gallery Control Items field with the help of output parameters from “Gallery Pagination” component.

    Here Gallery Pagination_1' is the “Gallery Pagination” component added on Canvas app screen.

     

    If('Gallery Pagination_1'.OutCurrentPage = 'Gallery Pagination_1'.OutTotalPages,

    LastN(FirstN(MySPCollection,'Gallery Pagination_1'.OutPageCounter),(InTotalItemsCount - ('Gallery Pagination_1'.OutPageCounter - 'Gallery Pagination_1'.OutItemsPerPage))),

    LastN(FirstN(MySPCollection,'Gallery Pagination_1'.OutPageCounter),'Gallery Pagination_1'.OutItemsPerPage))

     

     

    10.jpg

    Image 10

     

    You don’t have to worry about what each Output parameter is built but just for your information here are the details of Component output parameters:

    Output Parameter

    Description

    OutPageCounter

    Page counter for each page

    OutItemsPerPage

    Items shown per page

    OutCurrentPage

    Current Page Number

    OutTotalPages

    Total Page Number

     

    Note: If there are variables in your real Canvas app where you are using the same Input or Output variable names then you can go to the Component and update carefully the input or output variable names to new one which are used in Component’s OnReset event, Navigation control’s Select event and Page Numbers label control text. After this just save and publish the app and import component again in your canvas app. Now you will have to use new Input or Output variables in above steps.

     

     

     

    Step 11: Publish Canvas app

     

    Now save and publish the canvas app and open it in new browser window to let Screen OnVisible event execute correctly.

     

    11_1.jpg

    Image 11

     

    Step 12: Open Canvas app in browser

     

    Step 12.1: Go to the Apps view

     

    12_1.jpg

    Image 12.1

     

    Step 12.2: Open details of canvas app by using the context menu

     

    12_2.jpg
    Image 12.2

     

    Step 12.3: Copy or click on the Web link field to open the canvas app in browser

     

    Step 13: “Gallery Pagination” Component in action

     

    Canvas app results will look like this and now you can move back and forth to view paginated items using “Gallery Pagination” component. Here I have 16 items and based on my Gallery and Gallery Template Height, it shown me 4 pages.

     

    Step 13.1: On first page

     

    13_1.jpg

    Image 13.1

     

    Step 13.2: On second page

     

    13_2.jpg

    Image 13.2

     

    Step 13.3: On third page

     

    13_3.jpg

    Image 13.3

     

    Step 13.3: On last page

     

     

    13_4.jpg

    Image 13.4

     

    That’s It! 🙂

     

    Happy Learning, Anywhere! 🙂

    Gallery Pagination.msapp
    Labels:
    • Labels:
    • Components
    Message 1 of 2
    2,819 Views
    0 Kudos
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    pcakhilnadh
    pcakhilnadh Helper V
    Helper V
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-29-2021 01:09 AM

    This solution has delegation issues

    Message 2 of 2
    1,581 Views
    0 Kudos
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    Browse

    • Sample apps
    • Services

    Downloads

    • Windows
    • iOS
    • Android

    Learn

    • Documentation
    • Support
    • Community
    • Give feedback
    • Blog
    • Partners

    • © 2023 Microsoft
    • Follow Power Apps
    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices