New sortable_columns option in metadata.json to control sort options

You can now explicitly set which columns in a table can be used for sorting
using the _sort and _sort_desc arguments using metadata.json:

    {
        "databases": {
            "database1": {
                "tables": {
                    "example_table": {
                        "sortable_columns": [
                            "height",
                            "weight"
                        ]
                    }
                }
            }
        }
    }

Refs #189
This commit is contained in:
Simon Willison 2018-04-08 21:58:25 -07:00 committed by Simon Willison
commit b13f0986f2
7 changed files with 93 additions and 23 deletions

View file

@ -1,15 +1,15 @@
<table>
<thead>
<tr>
{% for i, column in enumerate(display_columns) %}
{% for column in display_columns %}
<th scope="col">
{% if i == 0 or disable_sort %}
{{ column }}
{% if not column.sortable %}
{{ column.name }}
{% else %}
{% if column == sort %}
<a href="{{ path_with_added_args(request, {'_sort_desc': column, '_sort': None, '_next': None}) }}" rel="nofollow">{{ column }}&nbsp;</a>
{% if column.name == sort %}
<a href="{{ path_with_added_args(request, {'_sort_desc': column.name, '_sort': None, '_next': None}) }}" rel="nofollow">{{ column.name }}&nbsp;</a>
{% else %}
<a href="{{ path_with_added_args(request, {'_sort': column, '_sort_desc': None, '_next': None}) }}" rel="nofollow">{{ column }}{% if column == sort_desc %}&nbsp;▲{% endif %}</a>
<a href="{{ path_with_added_args(request, {'_sort': column.name, '_sort_desc': None, '_next': None}) }}" rel="nofollow">{{ column.name }}{% if column.name == sort_desc %}&nbsp;▲{% endif %}</a>
{% endif %}
{% endif %}
</th>

View file

@ -8,7 +8,7 @@
<style>
@media only screen and (max-width: 576px) {
{% for column in display_columns %}
td:nth-of-type({{ loop.index }}):before { content: "{{ column|escape_css_string }}"; }
td:nth-of-type({{ loop.index }}):before { content: "{{ column.name|escape_css_string }}"; }
{% endfor %}
}
</style>