Requirement: Adding Pagination to Power apps Galleries
Adding Pagination in power apps galleries the users can hold the pagination controls to navigate through the items in the gallery by holding the next, previous, first and last buttons. I have provided the users with filters so they can filter the items in the gallery and also select the pagination size dynamically all of this keeping performance and Optimization in mind with large data source.
Here is the SharePoint list named “Large data”, we are using this records as data source.

Create a Canvas app, add galleries, buttons, Dropdown, Text Input and Labels controls to the screen.
- In this Scenario I have a data source that is a SharePoint list that has 40 records so we can deal with a large data set.
- In this screen we are looking at a gallery control that is showcasing me all the data from SharePoint list
- Also I have added a few filters so the user can go head and filter the data in the gallery
- I have a pagination logic that has been defined that will paginate through set of records based on the page size that user has defined.
Screen- OnVisible Property: Set(varPageNumber,1);
Drop Down(drpPaginationSize)-
Items Property: ["",5,10,15,20,25,30,35,40]
Drop Down(drpRegion)-
Items Property: Choices('Large data'.Region)
Label (lblCountRows)-
Visible Property: false
Text Property: CountRows(GalPersonMain.AllItems)
Gallery(GalPersonMain)-
Items Property: Filter('Large data', varReset && StartsWith('Person Name', txtPersonName.Text)&&(Region.Value= drpRegion.Selected.Value|| IsBlank(drpRegion.Selected.Value)))
Visible Property: false
Gallery(GalPersonInfo)-
Items Property:If(
iconNext.DisplayMode = DisplayMode.Disabled,
LastN(
FirstN(
GalPersonMain.AllItems,
drpPaginationSize.Selected.Value * varPageNumber
),
drpPaginationSize.Selected.Value - (drpPaginationSize.Selected.Value * varPageNumber-Value(lblCountRows.Text))
),
LastN(
FirstN(
GalPersonMain.AllItems,
drpPaginationSize.Selected.Value * varPageNumber
),
drpPaginationSize.Selected.Value
)
)
Icon (iconFirst)-
OnSelect Property: Set(varPageNumber,1)
Icon (iconPrevious)-
OnSelect Property:Set(varPageNumber, varPageNumber-1)
label(lblPagenumber)-
Text Property: "Page" & varPageNumber & "of" & If(Mod(CountRows(GalPersonMain.AllItems),100)=0, RoundUp(CountRows(GalPersonMain.AllItems)/ drpPaginationSize.SelectedText.Value,0) & "+pages",RoundUp(CountRows(GalPersonInfo.AllItems)/ drpPaginationSize.SelectedText.Value,0) & "page(s)")
Icon(iconNext)-
OnSelect Property:Set(varPageNumber,varPageNumber+1)

