Table clicksort is lost when using views exposed filter

Created on 30 October 2016, over 7 years ago
Updated 24 May 2024, about 1 month ago

Problem/Motivation

Original problem report, as amended by @mpp:

  • Create a paged view with an exposed block and expose the "items per page" option to allow a user to change the amount of results.
  • When applying a sort on the view and then changing the amount of items per page, the sort is lost.

Steps to reproduce:

  1. Installed fresh drupal(8.4.x), enabled devel, devel_generate modules
  2. Generated 50 contents(page, articles) from devel generate page -'/admin/config/development/generate/content'
  3. Created view page '/test' & select Title, Id fields
  4. Selected table format & enabled Title, Id as sort-able in it's table settings
  5. Selected Pager as full, and in it's settings checked 'Allow user to control the number of items displayed in this view' under 'EXPOSED OPTIONS' section
  6. Under Advanced settings, enabled 'Exposed form in block' option (Yes). And saved the view
  7. Next, i'v enabled this filter block from block layout page in one of the region & only for '/test' page
  8. Now, i visited '/test' page and clicked on title to sort it. Results came as expected & url is - http://d8.dev/test?items_per_page=5&order=title&sort=asc
  9. Next, from the block filter i'v changed no.of items to 25 & clicked apply. Results came only for this filter But sort queries gone in the url. url is - http://d8.dev/test?items_per_page=25

Also see this related issue which may be encountered when testing this bug: πŸ› Views exposed form block options are not updated immediately when adding additional sorts, filters, etc (Caching?) Needs work .

Proposed resolution

Atm the views exposed form filters out get parameters in ViewsExposedForm::buildForm:

$form['#action'] = $view->hasUrl() ? $view->getUrl()->toStrin- g() : Url::fromRoute('<current>')->toString();

A quick workaround would be to alter the exposed block form to add current sort & order query parameters.

Remaining tasks

User interface changes

(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)

API changes

(API changes/additions that would affect module, install profile, and theme developers, including examples of before/after code if appropriate.)

Data model changes

(Database or configuration data changes that would make stored data on an existing site incompatible with the site's updated codebase, including changes to hook_schema(), configuration schema or keys, or the expected format of stored data, etc.)

Original report by [username]

(Text of the original report, for legacy issues whose initial post was not the issue summary. Use rarely.)

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium mpp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.69.0 2024