Skip to content

Commit ba7956f

Browse files
committed
enhance pagination docs examples
1 parent 6d1c7c9 commit ba7956f

File tree

1 file changed

+55
-34
lines changed

1 file changed

+55
-34
lines changed

examples/official-site/sqlpage/migrations/70_pagination.sql

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
INSERT INTO component(name, icon, description, introduced_in_version) VALUES
22
('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.
55
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.
78
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.
1211
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.
1435
', '0.40.0');
1536

1637
INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'pagination', * FROM (VALUES
@@ -49,16 +70,16 @@ VALUES (
4970
},
5071
{
5172
"contents": 1,
52-
"link": "?page=1",
73+
"link": "?component=pagination&page=1",
5374
"active": true
5475
},
5576
{
5677
"contents": 2,
57-
"link": "?page=2"
78+
"link": "?component=pagination&page=2"
5879
},
5980
{
6081
"contents": 3,
61-
"link": "?page=3"
82+
"link": "?component=pagination&page=3"
6283
}
6384
]'
6485
)
@@ -74,16 +95,16 @@ VALUES (
7495
},
7596
{
7697
"contents": 1,
77-
"link": "?page=1",
98+
"link": "?component=pagination&page=1",
7899
"active": true
79100
},
80101
{
81102
"contents": 2,
82-
"link": "?page=2"
103+
"link": "?component=pagination&page=2"
83104
},
84105
{
85106
"contents": 3,
86-
"link": "?page=3"
107+
"link": "?component=pagination&page=3"
87108
}
88109
]'
89110
)
@@ -99,16 +120,16 @@ VALUES (
99120
},
100121
{
101122
"contents": 1,
102-
"link": "?page=1",
123+
"link": "?component=pagination&page=1",
103124
"active": true
104125
},
105126
{
106127
"contents": 2,
107-
"link": "?page=2"
128+
"link": "?component=pagination&page=2"
108129
},
109130
{
110131
"contents": 3,
111-
"link": "?page=3"
132+
"link": "?component=pagination&page=3"
112133
}
113134
]'
114135
)
@@ -120,26 +141,26 @@ VALUES (
120141
'[
121142
{
122143
"component": "pagination",
123-
"first_link": "?page",
144+
"first_link": "?component=pagination",
124145
"first_disabled": true,
125-
"previous_link": "?page",
146+
"previous_link": "?component=pagination",
126147
"previous_disabled": true,
127148
"next_link": "#?page=2",
128149
"last_link": "#?page=3"
129150
130151
},
131152
{
132153
"contents": 1,
133-
"link": "?page=1",
154+
"link": "?component=pagination&page=1",
134155
"active": true
135156
},
136157
{
137158
"contents": 2,
138-
"link": "?page=2"
159+
"link": "?component=pagination&page=2"
139160
},
140161
{
141162
"contents": 3,
142-
"link": "?page=3"
163+
"link": "?component=pagination&page=3"
143164
}
144165
]'
145166
)
@@ -155,26 +176,26 @@ VALUES (
155176
"last_title": "Last",
156177
"previous_title": "Previous",
157178
"next_title": "Next",
158-
"first_link": "?page",
179+
"first_link": "?component=pagination",
159180
"first_disabled": true,
160-
"previous_link": "?page",
181+
"previous_link": "?component=pagination",
161182
"previous_disabled": true,
162183
"next_link": "#?page=2",
163184
"last_link": "#?page=3"
164185
165186
},
166187
{
167188
"contents": 1,
168-
"link": "?page=1",
189+
"link": "?component=pagination&page=1",
169190
"active": true
170191
},
171192
{
172193
"contents": 2,
173-
"link": "?page=2"
194+
"link": "?component=pagination&page=2"
174195
},
175196
{
176197
"contents": 3,
177-
"link": "?page=3"
198+
"link": "?component=pagination&page=3"
178199
}
179200
]'
180201
)
@@ -194,35 +215,35 @@ VALUES (
194215
},
195216
{
196217
"contents": 1,
197-
"link": "?page=1"
218+
"link": "?component=pagination&page=1"
198219
},
199220
{
200221
"contents": 2,
201-
"link": "?page=2"
222+
"link": "?component=pagination&page=2"
202223
},
203224
{
204225
"contents": 3,
205-
"link": "?page=3"
226+
"link": "?component=pagination&page=3"
206227
},
207228
{
208229
"contents": 4,
209-
"link": "?page=4",
230+
"link": "?component=pagination&page=4",
210231
"active": true
211232
},
212233
{
213234
"contents": 5,
214-
"link": "?page=5"
235+
"link": "?component=pagination&page=5"
215236
},
216237
{
217238
"contents": 6,
218-
"link": "?page=6"
239+
"link": "?component=pagination&page=6"
219240
},
220241
{
221242
"offset": true
222243
},
223244
{
224245
"contents": 99,
225-
"link": "?page=99"
246+
"link": "?component=pagination&page=99"
226247
},
227248
]'
228249
)

0 commit comments

Comments
 (0)