Problem/Motivation
When a View, meant to be sorted in-place, has Views render-caching enabled, sorts are never saved.
Steps to reproduce:
- Create a View of fields where sorting is handled by Draggable Views,
- Add the Draggable Views sorting handler field to the View, so that it's possible to sort the view in-place,
- Enable Views render caching (time-based) under the advanced pane,
- Attempt to sort the View in-place.
Not only will the View not change (which is an existing UX issue related to Views caching and draggable views in general), but even if you flush all caches after attempting to sort, your sort order will not be reflected.
If you only enable query caching, the View sort will be reflected, but only after a cache clear (separate issue).
Proposed resolution
At the heart of the issue is the fact that form processing only happens when a form is attempted to be built (and there happens to be form data for processing). When Views render cache is used, the form doesn't have to be re-built (its contents/markup have already been built, rendered, and cached, so there's no need). Because the form is never re-built, it's never processed, and thus, the submitted sort order is never saved.
Workarounds
- If you must cache your rendered View, instead of using in-place sorting, just create a separate, un-cached View for sorting purposes
- If Views render caching is less of a priority for you compared to admin UX, then just disable Views render caching for that View
Possible resolutions
- Reasonable mitigation: Provide some sort of warning to end-users when in-place sorting and Views render cache are used on the same page. Even better, detect when this is attempted and just prevent the user from ever saving this configuration set.
- Non-ideal solution: Perhaps in a hook_init(), listen for all POST requests and detect when a draggable views sort can be (and has been) submitted. If so, process the form right then and there.
- Give up: Just document (on the project page and in the README) that Views render cache + in-place sorting is not supported and provide the workarounds described above.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | in_place_sorting_will-2176097-21.patch | 2.86 KB | istryker |
Comments
Comment #1
iamEAP commentedIssue title grammar fail...
Comment #2
iamEAP commentedUpdating the issue summary after further investigation...
Comment #3
nicxvan commentedI am getting the same behavior, shutting off caching didn't help.
I'm seeing a lot of issues in the queue relating to this module not working. I feel something should be on the module page.
Comment #4
nicxvan commentedCreating a separate view for the sorting didn't work either. I tried both a separate display and a separate view.
Changing priority since I see many related issues that don't seem to be getting attention.
Comment #5
betoscopioI have had this same problem. Seems to work well if the view have simple filter criteria. If a have a more complex view, using relationships of any kind the results could be not what you spect.
When you define the "sort criteria" for your view, you must not select any relationship even if you used a relationship as a filter criteria for your view. Changing this, my draggable view started to work again.
Comment #6
dsquaredb commentedSame issue on my site with sort order not saving. My view has a relationship but there are no filters using that relationship. However, the site is a view of content that anonymous and authenticated users have flagged (Flag module along with Session API for anonymous flagging), so the Draggableviews: Flags field has the flag relationship. If I use the Draggableviews: Content field, I cannot drag the view, only sort by weight, and still cannot save the order.
Comment #7
dsquaredb commentedUpdating to 7.x-2.0+56-dev saves the draggable sorting on my site. Others have reported in this issue that it also works for dragging but not for sorting by weight.
Comment #8
istryker commentedStop adding comment when it has nothing to do with the topic (CACHING), it is related to something else.
Moving back to normal priority as there are workarounds.
Comment #9
istryker commentedI create a test view of this and confirm that the display is not working
For the Native handler it is saving the order to the database, however it is not display the results.
Comment #10
istryker commentedFound this in views_bulk_operations_form_alter()
VBO does a lot of similar things that draggabeviews does, and caching is one of them
Comment #11
istryker commentedNevermind #10 does not work.
Comment #12
annya commentedThis patch fixes the following:
1.
Clear views cache after each submit of draggable view. We clear cache only for current view.
2.
Validation for draggableviews_handler_field_draggable has been added.
Please test and review this patch.
Comment #13
istryker commentedBefore testing.
#1 - We should not prevent the view from being save, rather, displays a warning. The goal is to warn the user that the views display cache will be cleared on each save.
Testing #12 patch - View with caching enabled:
1. Clear cache
2. Go to view and change order works.
3. Repeat #2 works until you refresh the page. Once you refresh the page, it does not fire draggableviews_form_alter() until cache expires and/or cache is cleared. This is where we add the
#submit = 'draggableviews_views_submit', which saves the order and, with this patch, clears the cache for the view.Comment #14
istryker commentedI was looking at other modules on how they handle this, and so far, no one has an answer.
Fiverstar - #2297231: Fivestar Not Working for Anonymous Users with Cache Enabled
VBO - #1307360: Node delete action doesn't fire if views cache is enabled.
So maybe we do need to throw an error message.
Comment #15
annya commentedCan't reproduce it. Are you sure you have disabled render cache for view? Because this patch doesn't fix problem with views render cahce, it fix problem with query view cache.
Comment #16
istryker commentedHow I turned on caching: In your view display -> other -> caching -> time based.
Comment #17
annya commentedYeah, but Render output should be set as Never cache. See screenshot
Comment #18
istryker commentedSee your screenshot. That makes sense now. The results are cache but the HTML/form is not. Should work.
Comment #19
annya commentedWith this patch we don't prevent views save and only show a warning message about incompatibility of Draggable Views and view cache render.
Comment #20
istryker commented@ Comment #17 - I see what you mean now. I had both Query and Render set to X time. I double-checked and if you have query set to X, it still works
Possible improvements
Comment #21
istryker commentedForgot the patch to #20.
Comment #22
hobie17 commentedDraggable views does not work when you have a contextual filter. I had one: content type and it did not work. Removing the contextual filter fixed it.