Views sort criteria and click-sort table headers do not work together as expected

Created on 6 June 2019, about 5 years ago
Updated 20 July 2023, 11 months ago

Scenario:
* Have a table view with multiple columns
* All headers are click-sortable
* No default for click-sort headers
* Have multiple sort criteria, including some of the same fields as click-sortable headers

Options:
(1): "Override normal sorting if click sorting is used" disabled
(2): " Override normal sorting if click sorting is used" enabled

Expected behavior:
* Clicking a header will change sort precedence
* AND additional sort criteria will still be applied
* AND sort criteria in conflict with click-sort headers will be discarded

Observed behavior (1):
* Clicking a header takes precedence for sorting
* All sort criteria discarded completely

Observed behavior (2):
* Clicking a header does not impact sort precedence
* Clicking a header only changes sort order (ASC/DESC)

Example:
Events Listing
Headers: Company / Topic / Year
Sort criteria (before clicking table headers): Year (DESC), Company, Topic

If I click "Company", I expect the following ORDER BY to be applied:
Company, Year (DESC), Topic
Instead, what I see is:
option 1: Company
option 2: Year (DESC), Company, Topic

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open on Drupal.org β†’
    Environment: PHP 8.2 & MySQL 8
    last update 12 months ago
    Waiting for branch to pass
  • πŸ‡¨πŸ‡¦Canada mdolnik

    This patch modifies \Drupal\views\Plugin\views\style\Table::buildSortPost() to add existing sort filters after the click-sort has been processed.

    This will ensure that either value of Override normal sorting if click sorting is used will keep existing sort filters, but the checking will ensure the click-sort is sorted first, while un-checking will ensure the click-sort is sorted last.

  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    IS should be updated to include proposed solution

    As a bug will need a test case showing the problem.

    Thanks.

Production build 0.69.0 2024