You can simply use {{ pagination.getDirection() }} in your branch template to find the current sort direction (if any), and then customize your classes based on this.
{% set direction = pagination.getDirection() %} <th{% if pagination.isSorted('p.id') %} class="sorted {{ direction }}"{% endif %}> {{ knp_pagination_sortable(pagination, 'Id', 'p.id') }} </th>
But ... KNP has not yet combined this fix from this post: https://github.com/sroze/KnpPaginatorBundle/commit/3105a38714c6f89c590e49e9c50475f7a777009d
If there is no direction parameter specified, the current Paginator package throws an error.
So, until the patch is merged, you can still get the direction with a bit more detail:
{% set directionParam = pagination.getPaginatorOption('sortDirectionParameterName') %} {% set params = pagination.getParams() %} {% set direction = params[directionParam] is defined ? params[directionParam] : null %} <th{% if pagination.isSorted('p.id') %} class="sorted {{ direction }}"{% endif %}> {{ knp_pagination_sortable(pagination, 'Id', 'p.id') }} </th>
source share