I'm looking for some assistance in setting up a table view to be able to sort merged columns separately. At a high level I have the following view table:
First Name |
Last Name |
Age/Weight^ |
Ken |
Davidson |
Age: 42 Weight: 200 |
I have all three columns sortable, except that the third column only sorts by Age
, even though it has two possible sort options. Clicking the Age/Weight
will only sort by Age, there is no way that I can see to make it sortable by either Age or Weight.
I found a couple links here that don't seem overly optimistic, but I'm hoping that things have changed:
Edit
The more I look into this, the more I'm starting to think that the only way to do this is by providing a custom template views-view-table--custom-view-name.html.twig
and would need to overwrite the one section:
<tr>
{% for key, column in header %}
{% if column.default_classes %}
{%
set column_classes = [
'views-field',
'views-field-' ~ fields[key],
]
%}
{% endif %}
<th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
<div class="th-wrap">
{%- if column.wrapper_element -%}
<{{ column.wrapper_element }}>
{% if column.title == 'sort by Age/Weight' %}
<!-- Add two links hardcoding the URL appropriately -->
{% else %}
{%- if column.url -%}
<a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
{%- else -%}
{{ column.content }}{{ column.sort_indicator }}
{%- endif -%}
</{{ column.wrapper_element }}>
{% endif %}
{%- else -%}
{%- if column.url -%}
<a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
{%- else -%}
{{- column.content }}{{ column.sort_indicator }}
{%- endif -%}
{%- endif -%}
</div>
</th>
{% endfor %}
</tr>
Before I follow this path, does it seem like an optimal solution? The issue here is that I would lose the ability to display the sort indicator, since the column is still directly related to Age/Weight
(which is just Age) instead of the individual columns.
Is there a global variable available in the views-view-table
renderer that I would be able to check for the actual sort column? Is the URL available for parsing?