helloflask / bootstrap-flask

Bootstrap 4 & 5 helper for your Flask projects.
https://bootstrap-flask.readthedocs.io
Other
1.1k stars 189 forks source link

New feature: reversible sort links #290

Open neilmcguigan opened 1 year ago

neilmcguigan commented 1 year ago

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