enumerate(): label the pages of search results
Hard
A search page shows ri!perPage results per page, and each page link is labelled with the results that page holds. 10 results at 4 per page gives {"1-4", "5-8", "9-10"}: the last page holds whatever is left.
Watch out
- There is no list to loop over, only a count of pages.
ceiling()rounds a division up, so a part page still counts as a page. - Each page works out its own first and last result, and the last one can never go past the total.
Inputs
ri!total— Integer, the number of resultsri!perPage— Integer, at least 1
ri! Rule Inputs
ri!totalInteger10
ri!perPageInteger4
Example 1 — A short last page
Input: ri!total
10
Input: ri!perPage
4
Output:
{
"1-4",
"5-8",
"9-10"
}Example 2 — Pages fill exactly
Input: ri!total
8
Input: ri!perPage
4
Output:
{
"1-4",
"5-8"
}Example 3 — Fewer results than one page
Input: ri!total
3
Input: ri!perPage
5
Output:
{"1-3"}Example 4 — No results
Input: ri!total
0
Input: ri!perPage
4
Output:
{}Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter