Added sort direction to truncated search result views, and aligned the sort direction arrow with that used for the client-side tablesorter for untruncated results.

- Legacy-Id: 10910
This commit is contained in:
Henrik Levkowetz 2016-03-06 17:27:17 +00:00
parent 8291f169ae
commit fbbc094086
2 changed files with 19 additions and 4 deletions

View file

@ -349,10 +349,19 @@ def retrieve_search_results(form, all_types=False):
if hasattr(form.data, "urlencode"): # form was fed a Django QueryDict, not local plain dict
d = form.data.copy()
for h in meta['headers']:
d["sort"] = h["key"]
h["sort_url"] = "?" + d.urlencode()
if h['key'] == query.get('sort'):
sort = query.get('sort')
if sort.endswith(h['key']):
h['sorted'] = True
if sort.startswith('-'):
h['direction'] = 'desc'
d["sort"] = h["key"]
else:
h['direction'] = 'asc'
d["sort"] = "-" + h["key"]
else:
d["sort"] = h["key"]
h["sort_url"] = "?" + d.urlencode()
return (results, meta)

View file

@ -26,7 +26,13 @@
<th data-header="{{ h.key }}">
{% if "sort_url" in h %}
<a href="{{ h.sort_url }}">{{ h.title }}
{% if h.sorted %}<span class="fa fa-caret-down"></span>{% endif %}
{% if h.sorted and meta.max %}
{% if h.direction == "asc" %}
<span class="fa fa-caret-up"></span>
{% else %}
<span class="fa fa-caret-down"></span>
{% endif %}
{% endif %}
</a>
{% else %}
{{ h.title }}