Pagination
Pagination controls component.
Preview
Usage
views.py
python
from djust import LiveView
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.current_page = 3my_template.html
django
{% load theme_components %}
{% theme_pagination current_page=current_page total_pages=10 url_pattern='?page={}' %}Props
| Name | Type | Required | Default |
|---|---|---|---|
| current_page | int | required | — |
| total_pages | int | required | — |
| url_pattern | str | required | — |
| show_edges | bool | True | |
| css_prefix | str | — | |
| attrs | dict | — | |
| slot_prev | str | — | |
| slot_next | str | — |
Accessibility
| Requirement | Element | Attribute | Value |
|---|---|---|---|
| Pagination nav must have aria-label | nav | aria-label | Pagination |
Slots
slot_prev slot_next
Source & styles
| File | Path | Notes |
|---|---|---|
| template | djust_theming/components/pagination.html | Copy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/. |
| css | djust_theming/components.css | Defines 7 of this component's classes at line 653, 658, 667, 668, 669, 691, 702. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_components/components.css | Defines 2 of this component's classes at line 381, 387. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
CSS variables
--accent --accent-foreground --border --foreground --muted-foreground --primary --primary-foreground --radius
Template source — pagination.html
django
<nav class="{{ css_prefix }}pagination {% if attrs.class %}{{ attrs.class }}{% endif %}"
aria-label="Pagination"
{% if attrs.id %}id="{{ attrs.id }}"{% endif %}>
<ul class="{{ css_prefix }}pagination-list">
<li>
{% if slot_prev %}
{{ slot_prev|safe }}
{% elif current_page > 1 %}
<a href="{{ prev_url }}" class="{{ css_prefix }}pagination-prev" aria-label="Previous page">« Prev</a>
{% else %}
<span class="{{ css_prefix }}pagination-prev {{ css_prefix }}pagination-disabled" aria-disabled="true">« Prev</span>
{% endif %}
</li>
{% if show_edges and first_page != None %}
<li><a href="{{ first_url }}" class="{{ css_prefix }}pagination-link">1</a></li>
{% if first_ellipsis %}<li><span class="{{ css_prefix }}pagination-ellipsis">…</span></li>{% endif %}
{% endif %}
{% for page in page_range %}
<li>
{% if page.number == current_page %}
<span class="{{ css_prefix }}pagination-link {{ css_prefix }}pagination-active" aria-current="page">{{ page.number }}</span>
{% else %}
<a href="{{ page.url }}" class="{{ css_prefix }}pagination-link">{{ page.number }}</a>
{% endif %}
</li>
{% endfor %}
{% if show_edges and last_page != None %}
{% if last_ellipsis %}<li><span class="{{ css_prefix }}pagination-ellipsis">…</span></li>{% endif %}
<li><a href="{{ last_url }}" class="{{ css_prefix }}pagination-link">{{ total_pages }}</a></li>
{% endif %}
<li>
{% if slot_next %}
{{ slot_next|safe }}
{% elif current_page < total_pages %}
<a href="{{ next_url }}" class="{{ css_prefix }}pagination-next" aria-label="Next page">Next »</a>
{% else %}
<span class="{{ css_prefix }}pagination-next {{ css_prefix }}pagination-disabled" aria-disabled="true">Next »</span>
{% endif %}
</li>
</ul>
</nav>