2018-06-30 23:32:48 +00:00
|
|
|
{#
|
|
|
|
Sortable table headers ('<th></th>' blocks)
|
|
|
|
|
|
|
|
If you're using this macro then you must comply with convention and use following query parameters:
|
|
|
|
- query - search query
|
|
|
|
- page - current page for pager
|
|
|
|
- order-by - which column is currently used for orderring
|
|
|
|
- order - order direction ('asc' or 'desc')
|
|
|
|
|
|
|
|
'columns' argument must be an associative array like:
|
|
|
|
'Human readable column name' => 'propertyName'
|
|
|
|
#}
|
|
|
|
{% macro sortable_columns(columns) %}
|
|
|
|
{% set route = app.request.attributes.get('_route') %}
|
|
|
|
{% set query = app.request.query.get('query') %}
|
|
|
|
{% set page = app.request.query.get('page') %}
|
|
|
|
{% set orderBy = app.request.query.get('order-by') %}
|
|
|
|
{% set order = app.request.query.get('order') %}
|
|
|
|
{% for column, property in columns %}
|
2018-07-01 01:01:53 +00:00
|
|
|
{% set isCurrent = (property == orderBy) %}
|
2018-06-30 23:32:48 +00:00
|
|
|
<th scope="col">
|
|
|
|
{% if property is not null %}
|
|
|
|
<a href="{{ path(route, {
|
|
|
|
'query': query,
|
|
|
|
'page': page,
|
|
|
|
'order-by': property,
|
2018-07-01 01:01:53 +00:00
|
|
|
'order': (order and isCurrent) ? ('asc' == order|lower ? 'desc' : 'asc') : 'asc'
|
|
|
|
}) }}">
|
|
|
|
{% if order and isCurrent %}
|
|
|
|
<i class="fas fa-sort-{% if 'asc' == order|lower %}down{% elseif 'desc' == order|lower %}up{% endif %}"></i>
|
|
|
|
{% endif %}
|
|
|
|
{% if isCurrent %}<b>{% endif %}{{ column | raw }}{% if isCurrent %}</b>{% endif %}
|
|
|
|
</a>
|
2018-06-30 23:32:48 +00:00
|
|
|
{% else %}
|
|
|
|
{{ column | raw }}
|
|
|
|
{% endif %}
|
|
|
|
</th>
|
|
|
|
{% endfor %}
|
|
|
|
{% endmacro %}
|