Skip to content

Commit 6dc6297

Browse files
committed
Move the facet and pagination references to Markdown
1 parent 71f181b commit 6dc6297

14 files changed

Lines changed: 337 additions & 391 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
icon: filter
3+
since: 0.46.0
4+
category: navigation
5+
summary: Let readers choose filters for a dataset.
6+
top:
7+
- name: all_active
8+
type: BOOLEAN
9+
description: Whether the link that clears the filter is active. Defaults to false.
10+
- name: all_link
11+
type: URL
12+
description: URL that clears the filter. If omitted, no All link is displayed.
13+
- name: all_title
14+
type: TEXT
15+
description: Text for the link that clears the filter. Defaults to "ALL".
16+
- name: center
17+
type: BOOLEAN
18+
description: Whether to center the facet selector
19+
- class
20+
- name: compact
21+
type: BOOLEAN
22+
description: Displays the facets in a dropdown instead of links.
23+
- name: description
24+
type: TEXT
25+
description: The facet category label.
26+
- name: dropdown_title
27+
type: TEXT
28+
description: Text shown on the compact-mode dropdown button when no facet is selected. Defaults to `Choose
29+
facet`.
30+
- id
31+
- name: selected_facet
32+
type: TEXT
33+
description: An alias for `dropdown_title`.
34+
row:
35+
- name: active
36+
type: BOOLEAN
37+
description: Whether the link is active or not. Defaults to false.
38+
- name: link
39+
type: URL
40+
required: true
41+
description: URL for the facet.
42+
- name: title
43+
type: TEXT
44+
required: true
45+
description: Facet title.
46+
---
47+
48+
Navigation links for filtering a dataset by a category, status, owner, or other attribute.
49+
50+
This component only renders the filter navigation. **Your SQL query is responsible for filtering the data** based on the URL parameter selected by the user.
51+
52+
Use it alongside a [table](?component=table), [list](?component=list), or [card](?component=card). The links use GET parameters, so the selected filter can be bookmarked and shared.
53+
54+
Set `compact` to display the facets in a dropdown, which is useful for a moderate number of choices or on narrow screens. Use `selected_facet` to show the active facet in the closed dropdown. `all_link` and `all_title` add a link that clears the filter.
55+
56+
The following portable pattern filters a table by category. `sqlpage.link` preserves the current page path while safely generating the URL.
57+
58+
```sql
59+
select 'table' as component;
60+
select title, category
61+
from my_table
62+
where $category is null or category = $category;
63+
64+
select 'facet' as component,
65+
'Category' as description,
66+
sqlpage.link(sqlpage.path(), json_object('category', null)) as all_link,
67+
$category is null as all_active;
68+
select category as title,
69+
sqlpage.link(sqlpage.path(), json_object('category', category)) as link,
70+
category = $category as active
71+
from my_table
72+
group by category
73+
order by category;
74+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
rows:
3+
- component: table
4+
- name: USS Enterprise (NCC-1701)
5+
class: Constitution
6+
- name: USS Exeter (NCC-1672)
7+
class: Galaxy
8+
- name: USS Exeter (NCC-1672)
9+
class: Constitution
10+
- component: facet
11+
description: Classes
12+
all_link: ?component=facet
13+
all_title: All
14+
all_active: false
15+
- title: Constitution
16+
link: ?component=facet&class=Constitution
17+
active: true
18+
- title: Galaxy
19+
link: ?component=facet&class=Galaxy
20+
---
21+
22+
A category selector with an All link. In an application, the SQL pattern above uses the chosen URL parameter to filter the displayed data.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
rows:
3+
- component: table
4+
- name: USS Enterprise (NCC-1701)
5+
class: Constitution
6+
- name: USS Defiant (NCC-1764)
7+
class: Constitution
8+
- name: USS Exeter (NCC-1672)
9+
class: Constitution
10+
- component: facet
11+
description: Classes
12+
all_link: ?component=facet
13+
all_title: All
14+
all_active: false
15+
compact: true
16+
dropdown_title: Select a spaceship class
17+
selected_facet: Constitution
18+
- title: Constitution
19+
link: ?component=facet&class=Constitution
20+
active: true
21+
- title: Galaxy
22+
link: ?component=facet&class=Galaxy
23+
---
24+
25+
Compact mode displays the facet choices in a dropdown.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
rows:
3+
- component: pagination
4+
- contents: 1
5+
link: ?component=pagination&page=1
6+
active: true
7+
- contents: 2
8+
link: ?component=pagination&page=2
9+
- contents: 3
10+
link: ?component=pagination&page=3
11+
---
12+
13+
This is an extremely simple example of a pagination component that displays only the page numbers, with the first page being the current page.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
rows:
3+
- component: pagination
4+
outline: true
5+
- contents: 1
6+
link: ?component=pagination&page=1
7+
active: true
8+
- contents: 2
9+
link: ?component=pagination&page=2
10+
- contents: 3
11+
link: ?component=pagination&page=3
12+
---
13+
14+
The ouline style adds a rectangular border to each navigation link.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
rows:
3+
- component: pagination
4+
circle: true
5+
- contents: 1
6+
link: ?component=pagination&page=1
7+
active: true
8+
- contents: 2
9+
link: ?component=pagination&page=2
10+
- contents: 3
11+
link: ?component=pagination&page=3
12+
---
13+
14+
The circle style adds a circular border to each navigation link.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
rows:
3+
- component: pagination
4+
first_link: ?component=pagination
5+
first_disabled: true
6+
previous_link: ?component=pagination
7+
previous_disabled: true
8+
next_link: '#?page=2'
9+
last_link: '#?page=3'
10+
- contents: 1
11+
link: ?component=pagination&page=1
12+
active: true
13+
- contents: 2
14+
link: ?component=pagination&page=2
15+
- contents: 3
16+
link: ?component=pagination&page=3
17+
---
18+
19+
The following example implements navigation links that can be enabled or disabled as needed. Since a navigation link does not appear if no link is assigned to it, you must always assign a link to display it as disabled.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
rows:
3+
- component: pagination
4+
first_title: First
5+
last_title: Last
6+
previous_title: Previous
7+
next_title: Next
8+
first_link: ?component=pagination
9+
first_disabled: true
10+
previous_link: ?component=pagination
11+
previous_disabled: true
12+
next_link: '#?page=2'
13+
last_link: '#?page=3'
14+
- contents: 1
15+
link: ?component=pagination&page=1
16+
active: true
17+
- contents: 2
18+
link: ?component=pagination&page=2
19+
- contents: 3
20+
link: ?component=pagination&page=3
21+
---
22+
23+
Instead of using icons, you can apply text to the navigation links.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
rows:
3+
- component: pagination
4+
first_link: '#?page=1'
5+
previous_link: '#?page=3'
6+
next_link: '#?page=4'
7+
last_link: '#?page=99'
8+
- contents: 1
9+
link: ?component=pagination&page=1
10+
- contents: 2
11+
link: ?component=pagination&page=2
12+
- contents: 3
13+
link: ?component=pagination&page=3
14+
- contents: 4
15+
link: ?component=pagination&page=4
16+
active: true
17+
- contents: 5
18+
link: ?component=pagination&page=5
19+
- contents: 6
20+
link: ?component=pagination&page=6
21+
- offset: true
22+
- contents: 99
23+
link: ?component=pagination&page=99
24+
---
25+
26+
If you have a large number of pages to display, you can use an offset to represent a group of pages.

0 commit comments

Comments
 (0)