Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for URL fragment in pagination button's link #154

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/sqlalchemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ automatically rendered through the ``render_pagination`` macro:
ellipses='…',\
size=None,\
args={},\
fragment='',\
**kwargs)

Renders a pager for query pagination.
Expand All @@ -39,5 +40,6 @@ automatically rendered through the ``render_pagination`` macro:
:param size: Can be 'sm' or 'lg' for smaller/larger pagination.
:param args: Additional arguments passed to :func:`~flask.url_for`. If
``endpoint`` is ``None``, uses :attr:`~flask.Request.args` and
:attr:`~flask.Request.view_args`
:attr:`~flask.Request.view_args`.
:param fragment: Add url fragment into link, such as ``#comment``.
:param kwargs: Extra attributes for the ``<ul>``-element.
9 changes: 5 additions & 4 deletions flask_bootstrap/templates/bootstrap/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
next=('&raquo;')|safe,
size=None,
ellipses='…',
args={}
args={},
fragment=''
)
-%}
{% with url_args = {} %}
Expand All @@ -26,13 +27,13 @@
<ul class="pagination{% if size %} pagination-{{size}}{% endif %}"{{kwargs|xmlattr}}>
{# prev and next are only show if a symbol has been passed. #}
{% if prev != None -%}
<li{% if not pagination.has_prev %} class="disabled"{% endif %}><a href="{{_arg_url_for(endpoint, url_args, page=pagination.prev_num) if pagination.has_prev else '#'}}">{{prev}}</a></li>
<li{% if not pagination.has_prev %} class="disabled"{% endif %}><a href="{{_arg_url_for(endpoint, url_args, page=pagination.prev_num) if pagination.has_prev else '#'}}{{fragment}}">{{prev}}</a></li>
{%- endif -%}

{%- for page in pagination.iter_pages() %}
{% if page %}
{% if page != pagination.page %}
<li><a href="{{_arg_url_for(endpoint, url_args, page=page)}}">{{page}}</a></li>
<li><a href="{{_arg_url_for(endpoint, url_args, page=page)}}{{fragment}}">{{page}}</a></li>
{% else %}
<li class="active"><a href="#">{{page}} <span class="sr-only">(current)</span></a></li>
{% endif %}
Expand All @@ -42,7 +43,7 @@
{%- endfor %}

{% if next != None -%}
<li{% if not pagination.has_next %} class="disabled"{% endif %}><a href="{{_arg_url_for(endpoint, url_args, page=pagination.next_num) if pagination.has_next else '#'}}">{{next}}</a></li>
<li{% if not pagination.has_next %} class="disabled"{% endif %}><a href="{{_arg_url_for(endpoint, url_args, page=pagination.next_num) if pagination.has_next else '#'}}{{fragment}}">{{next}}</a></li>
{%- endif -%}
</ul>
</nav>
Expand Down