I have been working on incorporating pagination into my repeating group and I’ve almost finished, but I’m stuck at this last part. Here’s what I’ve done so far.
I’m using a data type called Group which only has one field that I’ve called “Name”. I put a new RG into my page (called “Dashboard Group List”) with a fixed number of cells and I set the type to "Group”. I also set the data source to "Search for Groups”. At this point, each groups appears properly in its individual cell.
I wanted to approach pagination in a way that would allow me to bypass the default behavior which causes records to be repeated on the last page. To achieve this, I use custom states to do some math. The final product is the record number that my RG should start from when displaying records on the last page. I calculate that number with the following workflow:
When page is loaded
Step 1: Set state -> Element (Dashboard Group List) -> Custom state (groupsPerPage) -> Value (10)
Step 2: Set state -> Element (Dashboard Group List) -> Custom state (totalGroups) -> Value (Search for Groups:count)
Step 3: Set state -> Element (Dashboard Group List) -> Custom state (pagesTotal) -> Value (Search for Groups:count / Dashboard Group List’s groupsPerPage)
Step 4: Set state -> Element (Dashboard Group List) -> Custom state (roundNumber) -> Value (Dashboard Group List’s pagesTotal:floor)
Step 5: Set state -> Element (Dashboard Group List) -> Custom state (finalCalc) -> Value (Dashboard Group List’s roundNumber * Dashboard Group List’s groupsPerPage)
Step 6: Set state -> Element (Dashboard Group List) -> Custom state (startFrom) -> Value (Dashboard Group List’s finalCalc + 1)
Custom states recap:
groupsPerPage = This is the number of groups that should appear on one page at a time (10)
totalGroups = This is this total number of groups in my database (28)
pagesTotal = When I divide the number of groups by the number of groups in one page, I get the total number of pages (2.8)
roundNumber = I round the total number of pages down (2)
finalCalc = The last calculation where I multiply the total number of pages (in round number form) by the number of groups that appear per page (20)
startFrom= I take the last number and add 1, which leave me with the number of the first item on the last page (21)
I followed the RG pagination tutorial from @romanmg so I won’t repeat that here, but I have my RG list of numbers as well as Previous and Next buttons.
Here are the workflows:
When Button Previous is clicked
Step 1: Show previous of Dashboard Group List -> Element (Dashboard Group List)
When Button Page Number is clicked
Step 1: Go to page of Dashboard Group List -> Element (Dashboard Group List) -> Page (Current cell’s number)
When Button Next is clicked
Step 1: Show next of Dashboard Group List -> Element (Dashboard Group List)
By now my RG Dashboard Group List is functioning correctly. I can click the previous and next buttons to advance and go backward through the list and I can click any number and the page associated with that number will appear. But here’s where things break down.
In my RG I set a condition which says
When Dashboard Group List is on the last page
-> Data Source (Search for Groups:items from #Dashboard Group Lists’ startFrom)
After implementing this condition my previous, next and page number buttons no longer work and my RG is stuck on the last page permanently until I refresh. I can’t figure out if there’s supposed to be another condition where I reset the data or not. I’ve tried to create a workflow to reset the data whenever I press on any of the buttons, but it only ends up producing more strange behavior.
I’ve tried my best to replicate exactly what I’ve done in my app, so if anyone has feedback or ideas about what I’ve done wrong, it would be very much appreciated!