Comments

jg314’s picture

Version: 6.x-3.0-alpha3 » 7.x-3.0-rc1

Is there any way to remember the sort selection using rc1 for Drupal 7?

dawehner’s picture

This seems to be like a really really valid feature.

In general this remember code should probably be moved out of the filter specific thing perhaps to handlers in general
or perhaps it makes more sense in the exposed form plugin.

jg314’s picture

I definitely agree. So at this point it's not possible to have the sort remembered?

dawehner’s picture

StatusFileSize
new8.28 KB

Just some general work. Some testing would be nice, but please don't expect that it's working.

jg314’s picture

Awesome. Thanks a ton for posting it. I'll apply the patch and let you know how it goes.

ZuluWarrior’s picture

+100 for this!!!!

I to would love to see this functionality, I have a view with 2 slightly different page views. when you switch from one page view to another and back the exposed filters are remembered but the sort selector is not, hence the page switch re-orders all the filtered entries!

I will try out the patch too, and feedback in a few hours.

Is anyone still actively monitoring/working on this issue?

ZuluWarrior’s picture

Status: Active » Needs work

HI again,

The above patch can be applied to the latest 7.x-3.0-rc1 however I had to apply it manually as the line numbers are wrong!

Once applied, the patch does not cause any errors or erroneous behavior in the VIews UI (or with the site). However it doesn't work.

I have 5 exposed sort criterion, each one in turn exposes the order seelctor.

For example lets say they are :
> Most Recent (asc/desc) [Content:Post Date]
> Title (asc/desc) [Content:Title]
> Most Viewed (asc/desc) [Content:Views]
> Most Relivent (asc/desc) [Search:Score]
> By Credits (asc/desc) [Content:field_txt_credits]

No matter what the selection for 'Sort By' or 'Order', when transferring views the 'Sort By' returns to the top-most sort criteria, and the 'Order' is reset to Desc.

All the other filters work and are remembered (Term Search, Type ect) between transitions but not the Sory filters.

Anyone willing to advance this? I'm happy to work with someone coding this over the weekend, but need a guide through the murky waters that is the (extensive) views code and model.

dawehner’s picture

There is a big big reason why this patch was not even set to "needs work" :) But thanks for testing it!

@ZuluWarrior
The probably easiest and most effective way to get this feature in is to help in the issue queue with other issues.
This would really motivate people to test this feature, and you don't have to handle the views code.

terbs’s picture

StatusFileSize
new2.67 KB

I was able to get this function working by writing a tiny little module.

Basically, if you look in the $_SESSION variable you'll see where views is storing the remembered value for exposed filters, usually it's a key => value pair of the form field name paired with the value.

If you add key/value pairs to this array for the sort criteria views will obey them and set them as default for your sorts.

I'm attaching my module here for reference. This is how I got sort criteria to "remember" for my view "catalog".

plopesc’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new4.42 KB

Attaching new patch for this...

plopesc’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev

Updating version

Status: Needs review » Needs work

The last submitted patch, 10: remember_sort-1157104-10.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
StatusFileSize
new4.44 KB
new1.32 KB

Patch re-rolled with some improvements...

steveOR’s picture

Thanks @aiquandol for the useful working module code was able to play with it and include it in my own module.

erichomanchuk’s picture

I needed to update the patch as $this->view->display_handler->display->display_options['exposed_form']['options']['sort_remember'] no longer holds the values not sure if this is correct but only way I could get to the sort_remember values was to change to $this->view->display_handler->default_display->display->display_options['exposed_form']['options']['sort_remember']

erichomanchuk’s picture

StatusFileSize
new4.49 KB
jgullstr’s picture

Here's a patch that adds this functionality to table views.

jgullstr’s picture

Disregard previous patch, not working properly.

jenlampton’s picture

I'm using views Version: 7.x-3.11 and the patch in #16 adds the settings form, but does not save the sort order values. I think this is because it is pulling from the default display's settings, and not the current display. Attached patch fixes this, and combines #17 with #16.

jenlampton’s picture

And this removes the patch from #17. I somehow missed that it wasn't working appropriately.

mikeker’s picture

Perhaps out of scope, but this would leave the exposed pager as the only exposed option without a "remember" feature... (insert sad pager face here)

D8 version of this feature request: #2727751: Allow "remember selection" option for Views exposed sort and pager criteria.

markdc’s picture

Thanks for the work on this. I found some bugs.

The "Remember the last selection" setting is only accessible when "Expose sort order" is chosen. But IMO and according to OP, it should be a main setting whether you want to give users the Asc/Desc option or not.

In my case I have three Sort Criteria that I want to expose without Sort Order. I temporarily enable Sort Order to access and enable the Remember setting (for Authenticated role). The patch works as expected up to this point.

Bug 1
I disable Expose Sort Order to hide this secondary option as it doesn't fit my use case. Interestingly, the last selected Sort Criteria is still being remembered properly. However, I get the following error message everytime I load my view:

Notice: Undefined index: sort_order in views_handler_sort->store_exposed_input() (line 254 of /var/www/http/sites/all/modules/views/handlers/views_handler_sort.inc).

To get rid of the error message, I enable Expose Sort Order to gain access to and disable the Remember setting, and disable Expose Sort Order. Now I should be back to square one — no more remembering, right?

Bug 2
Wrong. The error messages are gone, but now the last Sort Criteria I had chosen before disabling Remembering has been permanently remembered. Every refresh loads the same Sort criteria (even if it's not the first in my View's list of criteria).

To get it to load the first criteria again by default, I have to temporarily enable Remembering, choose that Sort Criteria in my view, and disable Remembering. However, if I rearrange my View's Sort Criteria, the original order isn't be respected; the same criteria is still being remembered even after disabling this feature.

I'm testing on Views 7.x-3.18.

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old patch in #20 to views_handler_sort.inc and views_plugin_exposed_form.inc does not apply to the latest views 7.x-3.x-dev and additional work needed per the comments in #22.

Checking patch handlers/views_handler_sort.inc...
error: while searching for:
      '#required' => TRUE,
      '#size' => 40,
      '#weight' => -1,
   );
  }

  /**

error: patch failed: handlers/views_handler_sort.inc:196
error: handlers/views_handler_sort.inc: patch does not apply
Checking patch plugins/views_plugin_exposed_form.inc...
Hunk #1 succeeded at 49 (offset 5 lines).
Hunk #2 succeeded at 120 (offset 8 lines).
andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.31 KB

Patch rerolled.

sgdev’s picture

jenlampton created a patch to make this patch compatible with the Better Exposed Filters (BEF) module (https://www.drupal.org/project/better_exposed_filters/issues/2700031). However, this patch will not work if the "Combine sort order with sort by" option is enabled in BEF.

I have modified patch #24 to handle this consideration by adding a few extra lines to the end of the store_exposed_input function. It now works correctly with the #2700031 patch.

Please review, thanks.

sgdev’s picture

StatusFileSize
new5.38 KB

One further update... did some additional testing, and found a minor issue with the original patch.

The first time a view loads for a user, the value of $input has a possibility of being empty. This can generate the following watchdog errors:

Notice: Undefined index: sort_by in views_handler_sort->store_exposed_input() (line 274)
Notice: Undefined index: sort_order in views_handler_sort->store_exposed_input() (line 275)

This is fixed by adding isset checks for $input['sort_by'] and $input['sort_order'] when setting $session values.

See the attached patch, thanks.