Skip to content

New feature: reversible sort links#290

Open
neilmcguigan wants to merge 4 commits intohelloflask:mainfrom
neilmcguigan:master
Open

New feature: reversible sort links#290
neilmcguigan wants to merge 4 commits intohelloflask:mainfrom
neilmcguigan:master

Conversation

@neilmcguigan
Copy link

Added a new macro: render_sortlink. This renders hyperlinks to sort by a given field in a given direction, and its reverse

{{ render_sortlink('foo') }}

will render HTML:

<span class="text-nowrap">
        <a href="/?sort=foo,asc">Foo</a>
</span>

when clicked again, will render:

<span class="text-nowrap">
    <a href="/?sort=foo,desc">Foo</a>
    <svg class="bi" width="1em" height="1em" fill="currentColor">
        <use xlink:href="/bootstrap/static/icons/bootstrap-icons.svg#caret-up"></use>
    </svg>
</span>

when clicked again will render:

<span class="text-nowrap">
    <a href="/?sort=foo,asc">Foo</a>
    <svg class="bi" width="1em" height="1em" fill="currentColor">
        <use xlink:href="/bootstrap/static/icons/bootstrap-icons.svg#caret-down"></use>
    </svg>
</span>

maintains state with respect to other query string parameters

configurable to use different icons, or sort "styles", like ?sort=foo,asc vs ?field=foo&asc=1

@PanderMusubi PanderMusubi requested a review from greyli August 22, 2023 07:23
@PanderMusubi PanderMusubi added the enhancement New feature or request label Aug 22, 2023
@greyli
Copy link
Member

greyli commented Mar 9, 2025

Please update the documentation for the new macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants