You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/70_pagination.sql
+55-34Lines changed: 55 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,37 @@
1
1
INSERT INTO component(name, icon, description, introduced_in_version) VALUES
2
2
('pagination', 'sailboat-2', '
3
-
Pagination is a component that enables users to navigate through a large dataset.
4
-
The data is divided into pages, each containing a fixed number of rows.
3
+
Navigation links to go to the first, previous, next, or last page of a dataset.
4
+
Useful when data is divided into pages, each containing a fixed number of rows.
5
5
6
-
This component is typically used in conjunction with a table component.
6
+
This component only handles the display of pagination.
7
+
**Your sql queries are responsible for filtering data** based on the page number passed as a URL parameter.
7
8
8
-
The pagination component offers numerous customization features:
9
-
- It supports buttons to navigate to the first or last page, as well as the previous or next page.
10
-
- Navigation buttons can display text or icons.
11
-
- If the number of pages is too large, an offset can be used to enhance the component''s readability.
9
+
This component is typically used in conjunction with a [table](?component=table),
10
+
[list](?component=list), or [card](?component=card) component.
12
11
13
-
This component only handles the display of pagination. It must be dynamically generated by your code based on the volume of data to be presented to the user of your application.
12
+
The pagination component displays navigation buttons (first, previous, next, last) customizable with text or icons.
13
+
14
+
For large numbers of pages, an offset can limit the visible page links.
15
+
16
+
A minimal example of a SQL query that uses the pagination would be:
17
+
```sql
18
+
select ''table'' as component;
19
+
select * from my_table limit 100 offset $offset;
20
+
21
+
select ''pagination'' as component;
22
+
with recursive pages as (
23
+
select 0 as offset
24
+
union all
25
+
select offset + 100 from pages
26
+
where offset + 100 < (select count(*) from my_table)
27
+
)
28
+
select
29
+
(offset/100+1) as contents,
30
+
sqlpage.link(sqlpage.path(), json_object(''offset'', offset)) as link,
31
+
(offset/100+1 = $offset) as active from pages;
32
+
```
33
+
34
+
For more advanced usage, the [pagination guide](blog.sql?post=How+to+use+the+pagination+component) provides a complete tutorial.
0 commit comments