Select Page

Step 1: Add a gallery using the Blank template. Name it galHidden.

This Gallery will be used to query the data source. For the Items property of this gallery, define your query against your data source. Ensure that you are not running into any delegation warnings.

Set the Visible property of this gallery to false.

Click here to learn about delegation (working with large data sources in Power Apps).

Step 2: OnVisible of screen where Gallery is added, set the initial page number as follows: Set(varPageNumber,1)

Step 3: Create a dropdown control and name it drpPaginationSize

Set Items property for dropdown as follows:

[5,10,15]

Step 2: Add the Pagination controls to the screen.

Add 4 icon controls and 1 Label control.

Icon left:

OnSelect property –

Set(varPageNumber,1)

DisplayMode property –

If(
varPageNumber = 1,
Disabled,
DisplayMode.Edit
)

Icon arrow left:

OnSelect property –

Set(varPageNumber,varPageNumber-1)

DisplayMode property –

If(
varPageNumber = 1,
Disabled,
DisplayMode.Edit
)

Icon arrow right:

Name property –

icoNext

OnSelect property –

Set(varPageNumber,varPageNumber+1)

DisplayMode property –

If(
drpPaginationSize.Selected.Value * varPageNumber <= CountRows(galHidden.AllItems),
Edit,
Disabled
)

Icon right:

OnSelect property –

Set(varPageNumber, RoundUp( CountRows(galHidden.AllItems) / drpPaginationSize.SelectedText.Value ,0) )

DisplayMode property –

If(
drpPaginationSize.Selected.Value * varPageNumber <= CountRows(galHidden.AllItems),
Edit,
Disabled
)

Label:

Text property –

"Page " & varPageNumber & " of " & If(
Mod(
CountRows(galHidden.AllItems),
100
) = 0,
RoundUp( CountRows(galHidden.AllItems) / drpPaginationSize.SelectedText.Value ,0) & "+ pages",
RoundUp( CountRows(galHidden.AllItems) / drpPaginationSize.SelectedText.Value,0) & " page(s)"
)

Step 2: Add a second gallery to your screen. Name it galMain. This gallery will be used to present the data that is fetched from the hidden gallery. In order to implement pagination we would be leveraging the FirstN and LastN functions which are not delegable. However, since our hidden gallery galHidden will query our data source and get the records. We can query the items in our hidden gallery and apply the FirstN and LastN functions to paginate and not run into any delegation issues.

For the Items property of our gallery galMain use the following:

If(
icoNext.DisplayMode = Disabled,
// Handling last set of records
LastN(
FirstN(
galHidden.AllItems,
drpPaginationSize.Selected.Value * varPageNumber
),
drpPaginationSize.Selected.Value - (drpPaginationSize.Selected.Value * varPageNumber - CountRows(galHidden.AllItems))
),
LastN(
FirstN(
galHidden.AllItems,
drpPaginationSize.Selected.Value * varPageNumber
),
drpPaginationSize.Selected.Value
)
)

This should now setup the Pagination for your Gallery galMain.

Happy PowerApping!!!