The exposed sort feature added in Views 3 is very cool. Would be even more cool if it had a "remember" feature like exposed filters has. :)
The exposed sort feature added in Views 3 is very cool. Would be even more cool if it had a "remember" feature like exposed filters has. :)
Comments
Comment #1
jg314 commentedIs there any way to remember the sort selection using rc1 for Drupal 7?
Comment #2
dawehnerThis 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.
Comment #3
jg314 commentedI definitely agree. So at this point it's not possible to have the sort remembered?
Comment #4
dawehnerJust some general work. Some testing would be nice, but please don't expect that it's working.
Comment #5
jg314 commentedAwesome. Thanks a ton for posting it. I'll apply the patch and let you know how it goes.
Comment #6
ZuluWarrior commented+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?
Comment #7
ZuluWarrior commentedHI 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.
Comment #8
dawehnerThere 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.
Comment #9
terbs commentedI 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".
Comment #10
plopescAttaching new patch for this...
Comment #11
plopescUpdating version
Comment #13
plopescPatch re-rolled with some improvements...
Comment #14
steveOR commentedThanks @aiquandol for the useful working module code was able to play with it and include it in my own module.
Comment #15
erichomanchuk commentedI 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']
Comment #16
erichomanchuk commentedComment #17
jgullstr commentedHere's a patch that adds this functionality to table views.
Comment #18
jgullstr commentedDisregard previous patch, not working properly.
Comment #19
jenlamptonI'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.
Comment #20
jenlamptonAnd this removes the patch from #17. I somehow missed that it wasn't working appropriately.
Comment #21
mikeker commentedPerhaps 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.
Comment #22
markdcThanks 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:
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.
Comment #23
chris matthews commentedThe 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.
Comment #24
andrew answer commentedPatch rerolled.
Comment #25
sgdev commentedjenlampton 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_inputfunction. It now works correctly with the #2700031 patch.Please review, thanks.
Comment #26
sgdev commentedOne 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
$inputhas a possibility of being empty. This can generate the following watchdog errors:This is fixed by adding
issetchecks for$input['sort_by']and$input['sort_order']when setting$sessionvalues.See the attached patch, thanks.