The relationship between Sort Criteria and the sorting of Fields is unclear. From what I've seen by using Views in the field, if you actually specify and use the Sort Criteria, then clicking the column headings in Table view no longer sorts the results. The Sort Criteria are used in all cases, regardless of whether the user has chosen to sort the rows differently. Is this true or am I missing something?
Unless I'm mistaken about this behavior, this means that admins who are setting up table-style Views using Sort Criteria have to be aware that they should not make fields sortable under the "Fields" section because it will only confuse their site visitors. Visitors will still be able to click on column headings, but nothing will happen and the site will seem broken.
Because of this, I'd like to suggest that the Views module have a feature whereby it knows not to make columns sortable by field when Sort Criteria have been applied. In other words, whenever the admin has established Sort Criteria, Views then ignores the "Sortable" and "Default Sort" settings under "Fields" -- as if they had never been set. That way, when the View is themed, it doesn't present the ridiculous illusion that fields are still sortable. Should prevent confusion.
I also suggest that a warning should appear in the "Fields" section, saying something like "The Sortable and Default Sort settings here will be ignored if you have specified sort criteria below in the Sort Criteria section," and another warning in the "Sort Criteria" section saying something like, "These settings override any Sortable or Default Sort settings in the Fields section above."
Thank you, and I appreciate the great work!
Comments
Comment #1
noah10 commentedI've discovered what's actually happening here and I have a suggestion that I think might be easier to implement than the one above:
What's happening is that user-initiated sorts occur AFTER the Sort Criteria sorts are applied. I have a table, for example, that sorts job postings on date created and state. The users can also click on the column headers to sort by city, job type, etc. Here's what the order by clauses look like when a user clicks to sort by city:
ORDER BY node_created_created DESC, node_data_field_state_field_state_value ASC, node_data_field_city_field_city_value DESC
Unfortunately, this set of order by clauses makes the user think that sorting is broken, since they expect it to be sorted by city first.
Modifying the code so that user-initiated sorts are applied before Sort Criteria sorts would fix this - the results in the example above would be sorted by city, followed by date created and state. If folks with more experience in the internals of Views think that such a change would be helpful and not too likely to break anything else I'd be happy to take a crack at it and provide a patch if I'm successful. I'm also open to other solutions, but unfortunately the one you propose, Vallenwood, is the opposite of what I need - I could live with Sort Criteria being turned off when a user clicks on a column header to sort by field, but I can't live with turning off field sorting just because I've set Sort Criteria.
Comment #2
t10barba commentedJust delete the default "Sort Criteria".
Comment #3
noah10 commentedDeleting the default sort criteria isn't an option for me (not sure if your comment was addressed to me or to Vallenwood). They're there because we want the data sorted a certain way by default. Unless you know of a way to "delete" (read: Temporarily turn off) the default sort criteria only when a user-initiated sort has been applied then this solution doesn't work.
Note that in http://drupal.org/node/176506 I've already tracked down exactly where the problem is happening and provided a simple fix for it.
Comment #4
merlinofchaos commentedThis will not be fixed in Views 1.