This is a follow-on to #228510: Exposed Sorts. The exposed sorts do not properly default; all sorts appear. It can appear to work right, because the first sort in the list is going to appear in the sort gadget, but if that value has a lot of the same data (as is often the case when using devel generated data and dates) the secondary sorting will be wrong and provide inconsistent results when you hit apply.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | exposed_sorts_do_not_properly_default-666870-27.patch | 733 bytes | a.ross |
| #26 | 666870-26.patch | 553 bytes | jody lynn |
| #16 | 666870-views-exposed_sorts-2.patch | 1.31 KB | kenorb |
| #14 | views_plugin_exposed_form.inc-666870.patch | 1.08 KB | kenorb |
| #6 | 666870-6.views-exposed-sorts.patch | 1.64 KB | dww |
Comments
Comment #1
dawehneri got it
Comment #2
dwwSomehow I didn't find this while searching, and I just submitted a duplicate of this #800752: Exposed sort order dropdown doesn't reflect the active default order *doh*!
I just tried it and this patch definitely fixes the bug I was talking about. I can't say I grok exposed sorts yet, but a quick visual skim of the patch looks exactly like what I proposed at #800752. Small patch that I can confirm solves the bug I saw. I'll let the Views3 crew actually commit, but this looks RTBC to me.
Thanks!
-Derek
p.s. Shouldn't we add an "exposed sorts" component?
Comment #3
dawehnerI would like to have a exposed form component, there might be issues with other stuff, like exposed "items per page".
Would it be possible to rename a component?
PS:
Only earl commits to drupal-6--3
Comment #4
dwwWrong place for this discussion, but...
"Would it be possible to rename a component?"
#140989: Renaming components is unsafe -- still not there yet... :(
Comment #5
dwwDrat, I'm sorry to report that this patch appears to break the exposed sort order UI. :( While it defaults to the right thing with the patch, if you change the order in the UI and submit, the changed order is ignored and the query ends up always sorting DESC.
The combo of these two bugs is actively nailing me right now, so I'm going to debug a little more closely, stay tuned.
Comment #6
dwwHeh. Yeah, this was missing a critical piece. We were simply ignoring the exposed form value unless it was in (asc, desc), but the rest of the code was using ASC and DESC.
This seems like a fragile aspect of exposed sorts, since it varies across the views codebase whether we use asc vs. ASC.
The attached patch actually works in the case of the exposed sorts I'm dealing with, which is what I need to get working.
However, it'd probably be worth a more far-reaching review and plan around this problem, since I fear similar bugs will emerge in the future if we don't do something systematic.
Comment #7
rburgundy commentedsubscribe
Comment #8
Bilmar commentedApplied the patch and it fixed the issue with Exposed Sort Order not properly defaulting to Asc or Desc.
I came across this issue when testing #657148: Add support for Exposed Sort for BEF module.
Comment #9
merlinofchaos commentedApplied to both -dev branches.
I agree that we should consider finding something more systematic to prevent the case issue, but that is kind of a difficult problem. This fix will have to do for now.
Comment #11
scotjam commentedUnfortunately, I can't get this working.
I have two different sort criteria, both exposed for the user to select. Each sort criteria has a different default sort order. But, when the user selects a sort criteria the sort order is not updated to its pre-set default.
I'm I wrong in assuming that this fix should update the exposed-drop-down-selection-sort-order to reflect the default sort order of the sort criteria? I could have got the wrong end of the stick!
Hope someone can help!
cheers
scotjam
Comment #12
scotjam commentedFound how to get around it...
unset($form['sort_order']);
placed in a hook_form_alter.
That way, the sort_order doesn't get picked up, instead the default sort_order does.
Hope this helps
scotjam
Comment #13
kenorb commentedWhy we copying default order from the first sort?
What if we have more than one?
Marked as duplicate:
#1000160: Order of second exposed sort is copied from the first one when manually applying sort_by=title into URI
Comment #14
kenorb commentedPatch in attachment.
Problem described here:
#1000160: Order of second exposed sort is copied from the first one when manually applying sort_by=title into URI
Comment #15
merlinofchaos commentedThis looks like it's going to produce an inconsistent variable. i.e, if $form_state['input']['sort_order'] exists, it will be a string. If it does not exist, it will be a sort handler.
That means if $input_order existed in the input, then $input_order->options['order'] is going to be broken because it's a string, not a class.
Plus, we now have a $first_sort even though we didn't really need one.
Ultimately, if $form_state['input']['sort_order'] is actually set, our default_value doesn't really matter a whit because it'll be overridden by the input, so there is no point in checking that. What we care about is if sort_by is set and exists, in which case we can go ahead and use its value as our default.
And then '#default_value' is just $default_sort_order.
Does that do what you want?
Comment #16
kenorb commentedYes, that's correct. Tested and it does work in the same way.
Comment #17
dawehnerSorry.
It would be cool to fix the codestyle first
It should be have an extra line.
Comment #18
vistree commentedHi, I am not sure if my problem is the same as described here.
I added several exposed sorts. The first is descending. If I open the view, sorting is as aspected.
Now, I have a second exposed sort. This time it is ascending.
Looking at the view, both columns are sorted correctly.
But, if I change the sortfild in the dropdown (header of view) to the second value, the sorting is wrong. Instead of sorting the column asc (as set in the exposed filter), it is sorted descending (as the first column).
Can I fix this by applying the above patch?
Comment #19
dawehnerJust try out the patch.
Comment #20
dawehnerBased on #1061014: Exposed sort ignores sorting set for each field #18 requests a new feature which will not be fixed with this patch.
Comment #21
dawehnerPerhaps you should ignore me and just try out the patch :)
Comment #22
vistree commentedHi, thank you for your reply.
I applied the patch from #16, but there is no diffence afterwards. Do I have to modify the patch somehow? Is there something in #17 I have to apply?
Comment #23
Drupi commentedThe same bug seems to be in Drupal 7, too.
Can anyone provide a patch similar to patch #16 for the current 7.x-3.x-dev version, that addresses the problem? That would be great!
Comment #24
dawehnerThis pach works for 7.x, too
Comment #25
Drupi commentedThanks for your quick response, dereine. Unfortunately, I'm having the same problem as vistree and the patch doesn't work here either.
Do you have any ideas?
Comment #26
jody lynnThe patch in #16 looks to be already applied. However it fixed the default sort_by but not the default sort_order.
Currently if you have multiple exposed sorts it's impossible to have a default sort. I would expect it to default to the first sort since that is what it shows in the UI.
This patch adds the first sort as the default sort.
Comment #27
a.ross commentedI'm not sure if I grok #26, but I'm also having an issue with the default sort order of exposed filters. The default sort order is incorrect when the exposed filter is below a regular filter (like "node: sticky"). It in fact uses the sort order for the first filter, even if that isn't an exposed filter.
Comment #28
Media Crumb commentedDo patch 26 and 27 fix this issue?
Comment #29
ryan.ryan commentedThanks Jody, exactly what I needed. :) #26 is what I needed.
Comment #30
dobe commentedThis patch is relevant but seems to be kinda old. I re-rolled a patch at https://www.drupal.org/node/2037469#comment-11023513
So I am going to mark as duplicate and hopefully we can get the other one pushed.
Thanks to everyone who has contributed to this issue. I have requested that all involved here get credit for the other issues queue.