|
| 1 | +--- |
| 2 | +icon: sailboat-2 |
| 3 | +since: 0.40.0 |
| 4 | +category: navigation |
| 5 | +summary: Link to other pages of a query result. |
| 6 | +top: |
| 7 | + - name: circle |
| 8 | + type: BOOLEAN |
| 9 | + description: Whether to use circle version of the pagination. |
| 10 | + - class |
| 11 | + - name: first_disabled |
| 12 | + type: BOOLEAN |
| 13 | + description: disables the button to go to the first page. |
| 14 | + - name: first_link |
| 15 | + type: URL |
| 16 | + description: A target URL to which the user should be directed to get to the first page. If none, the link |
| 17 | + is not displayed. |
| 18 | + - name: first_title |
| 19 | + type: TEXT |
| 20 | + description: The text displayed on the button to go to the first page. |
| 21 | + - id |
| 22 | + - name: last_disabled |
| 23 | + type: BOOLEAN |
| 24 | + description: disables the button to go to the last page. |
| 25 | + - name: last_link |
| 26 | + type: URL |
| 27 | + description: A target URL to which the user should be directed to get to the last page. If none, the link |
| 28 | + is not displayed. |
| 29 | + - name: last_title |
| 30 | + type: TEXT |
| 31 | + description: The text displayed on the button to go to the last page. |
| 32 | + - name: next_disabled |
| 33 | + type: BOOLEAN |
| 34 | + description: Disables the button to go to the next page. |
| 35 | + - name: next_link |
| 36 | + type: URL |
| 37 | + description: A target URL to which the user should be directed to get to the next page. If none, the link |
| 38 | + is not displayed. |
| 39 | + - name: next_title |
| 40 | + type: TEXT |
| 41 | + description: The text displayed on the button to go to the next page. |
| 42 | + - name: outline |
| 43 | + type: BOOLEAN |
| 44 | + description: Whether to use outline version of the pagination. |
| 45 | + - name: previous_disabled |
| 46 | + type: BOOLEAN |
| 47 | + description: disables the button to go to the previous page. |
| 48 | + - name: previous_link |
| 49 | + type: URL |
| 50 | + description: A target URL to which the user should be directed to get to the previous page. If none, the |
| 51 | + link is not displayed. |
| 52 | + - name: previous_title |
| 53 | + type: TEXT |
| 54 | + description: The text displayed on the button to go to the previous page. |
| 55 | +row: |
| 56 | + - name: active |
| 57 | + type: BOOLEAN |
| 58 | + description: Whether the link is active or not. Defaults to false. |
| 59 | + - name: contents |
| 60 | + type: INTEGER |
| 61 | + required: true |
| 62 | + description: Page number. |
| 63 | + - name: link |
| 64 | + type: URL |
| 65 | + description: A target URL to which the user should be redirected to view the requested page of data. |
| 66 | + - name: offset |
| 67 | + type: BOOLEAN |
| 68 | + description: Whether to use offset to show only a few pages at a time. Usefull if the count of pages is |
| 69 | + too large. Defaults to false |
| 70 | +--- |
| 71 | + |
| 72 | +Navigation links to go to the first, previous, next, or last page of a dataset. |
| 73 | +Useful when data is divided into pages, each containing a fixed number of rows. |
| 74 | + |
| 75 | +This component only handles the display of pagination. |
| 76 | +**Your sql queries are responsible for filtering data** based on the page number passed as a URL parameter. |
| 77 | + |
| 78 | +This component is typically used in conjunction with a [table](?component=table), |
| 79 | +[list](?component=list), or [card](?component=card) component. |
| 80 | + |
| 81 | +The pagination component displays navigation buttons (first, previous, next, last) customizable with text or icons. |
| 82 | + |
| 83 | +For large numbers of pages, an offset can limit the visible page links. |
| 84 | + |
| 85 | +This SQLite example uses the first page when no offset is supplied. Order by a unique key so successive pages have a stable order. |
| 86 | +```sql |
| 87 | +set offset = max(0, coalesce(cast($offset as integer), 0)); |
| 88 | +select 'table' as component; |
| 89 | +select * from my_table order by id limit 100 offset cast($offset as integer); |
| 90 | + |
| 91 | +select 'pagination' as component; |
| 92 | +with recursive pages as ( |
| 93 | + select 0 as offset |
| 94 | + union all |
| 95 | + select offset + 100 from pages |
| 96 | + where offset + 100 < (select count(*) from my_table) |
| 97 | +) |
| 98 | +select |
| 99 | + (offset/100+1) as contents, |
| 100 | + sqlpage.link(sqlpage.path(), json_object('offset', offset)) as link, |
| 101 | + offset = cast($offset as integer) as active |
| 102 | +from pages; |
| 103 | +``` |
| 104 | + |
| 105 | +For more advanced usage, the [pagination guide](blog.sql?post=How+to+use+the+pagination+component) provides a complete tutorial. |
0 commit comments