As a feature request, I'd like to see the ability to sort a contextual filter of taxonomy terms based on the weight of the terms.
Maybe I'm missing something, but it doesn't seem possible to do this in Views 3 at the moment.
The ability to create a contextual filter and sort by the weight of taxonomy terms would be a real bonus.
Sometimes taxonomy terms are presented in a specific, non-alphabetic order for a good reason.
For example, the terms might be numeric values that need to be presented in ascending order:
- 1.000-5.000
- 5.000-10.000
- 10.000-50.000
However, using the default Sort by Alphabetical option, these terms are presented as:
- 1.000-5.000
- 10.000-50.000
- 5.000-10.000
There does not appear to be any easy way to override this alphapetical sort and present the terms in ascending numeric order.
An option to sort by Taxonomy Term weight in the contextual filter editing pane would be an ideal way of adding this functionality.
Anyway, just a request. Thanks for all the work on Views. I'm constantly amazed by what this module can do.
Regards.
Comment | File | Size | Author |
---|---|---|---|
#3 | contextual-filter-editing-pane.png | 74.83 KB | moreorless |
#3 | contextual-filter-example.png | 61.92 KB | moreorless |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedHow do you sort a filter? I don't understand this request.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedOh, well. Ignoring the contextual filter, the database sorts strings as strings, not numbers. It's *really* hard to sort a string as a number. If you want to do that, you probably need to provide another hidden field that you do the sorting on. That is not something that will be 'fixed' because that's how databases work.
Strings and numbers sort differently. When you want to sort by your first list, what you're really sorting is the first number in the string. That is just not possible without some kind of transformation of the data.
Comment #3
moreorless CreditAttribution: moreorless commented"How do you sort a filter?"
Well it is an option in the contextual filter editing pane - 'Sort order' and 'Sort by' - see attached screenshot (contextual-filter-editing-pane.png) - so I thought my request would have made sense. Sorry if my explanation wasn't sufficiently clear.
What I'm trying to do is illustrated in the other attachment (contextual-filter-example.png).
I have a list of links to content with associated taxonomy terms.
I have created a contextual filter to filter that list based on the taxonomy terms.
When those terms are numeric the list in the contextual filter may not sort in ascending numeric order.
Thanks for pointing out that it's not possible to prevent this. Now I can start looking for a work-around.
Comment #4
Roi Danton CreditAttribution: Roi Danton commentedI'm in the same situation wanting to sort taxonomy terms by weight used in a contextual filter.
Is it possible to add another sort option for contextual filter -> summary view than Alphabetical or Number of Records - e.g. taxonomy weight?
Comment #5
sander-martijn CreditAttribution: sander-martijn commentedI also need this and need it often. Since a few got caught up in the numbers being stored as strings, I'll bring it back to the op's question with another example where weight based sorting is the only option (weights are already stored for taxonomy so this isn't a stretch of a request).
A designer needs to show their collections from newest to oldest. The collections are named:
Spring 2013
Fall 2012
Spring 2011
Bespoke commission by Kate Moss
Fall 2010
etc.
Or someone wants to list their clients (clickable to a gallery) and wants to keep the most important ones on the top to feature them more prominently.
Or lots of other reasons why you wouldn't want to show a list of terms in alphabetical order.
Comment #6
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedI am just adding my two cents here. I feel this has more to do with summary sorting than it does with taxonomy. If I am understanding correctly, the request really is to allow specifying alternate sort criteria for the default summary options. I agree that as it stands, these options are not extendable or editable beyond what is there by default.
Here is the code that currently creates the default summary sort options:
Note the fact that the array
$form['summary']['number_of_records']['#options']
is hardcoded and cannot be extended for more options through views plugins. This is an oversight or maybe an untapped feature.The direction I would like to see this take is to allow any field that is in the fields settings for a display would become available for sorting in these options. On a related note for implementation, it looks like the value of the setting is use to perform the ordering using:
Where
$order
is either asc or desc and$by
is the named alias of the field in the db which is currently not configurable beyond 'num_records' or the named alias coming from the field you are using in the contextual filter. Would be great to have the option to pick something else that is being selected in the current query.Comment #7
sander-martijn CreditAttribution: sander-martijn commentednicholas.alipaz' suggestion makes sense and should indeed solve all people's requirements - not only could you choose from any field, but if none of those work for you choose weight and sort the taxonomy the way you want it (which solves the example I posed). I hope these new comments raise the priority on this - I recently ran across the issue again, and unfortunately though I'm good with drupal and php and can make some modification to modules, I've never learned the module API well enough to attempt at messing with a module as complex as views!
Comment #8
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedChanging component since it isn't related directly to taxonomy.
Comment #9
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedChanging name to match the issue better.
Also, I had need to sort on taxonomy's weight in particular. I used the following to accomplish it:
To ascertain the data in these queries I used devel to
dpm($query);
inside of the main views displaypage
which had the field I wanted to sort by then I copied the field and field_alias from that view display. Lastly set the orderby field to the alias.Comment #10
timwoodSeems related or possible duplicate of https://drupal.org/node/417312.
Comment #11
nattyweb CreditAttribution: nattyweb commentedInterested in this - hoping to see a solution soon...