I have a view that groups its results by a taxonomy term (the term field is excluded from display so I only see the group headings that Views automatically displays when grouping is enabled).
I'd like to be able to sort the view results so that I see the group headings in alphabetical order. However, when I add the term field under 'Sorting', I can't acheive alphabetical sorting (tried both ascedning and descending sorting). I have noticed that the sorting appears to match the order in which I created the terms in the first place so I'm wondering if it's sorting by Term ID rather than the term's name.
I did check ad the terms are sorted alphbetically in their vocabulary.
I'm not sure whether this is a bug or not so have marked it as a support request for now.
Any help would be greatly appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | Screen Shot 2012-10-10 at 16.51.44.png | 102.1 KB | Szerge |
| #17 | Screen Shot 2012-10-10 at 16.51.34.png | 127.16 KB | Szerge |
Comments
Comment #1
dawehnerWell the problem is somehow easy, the field itself is stored as ID (a number) not as the term name.
To be able to sort by the term name/term weigth you would have to join to the term table itself.
So did you tryed to use taxonomy: term?
Comment #2
dddbbb commentedPerhaps I don't follow you but I don't see an option for 'taxonomy: term' as a sort option. I'm already sorting by the term under 'content' and that only provides the functionality I've already described.
In case there's any confusion, this is Views 3 under Drupal 7 that I'm referring to here.
Comment #3
JohnnyX commentedSame problem. I can only sort asc/ desc by term but not by name or weight. I have to order my categories (= terms) by weight.
Subscribe
Comment #4
tj2653 commentedI just came across the same issue with 7.x-3.0-rc1.
Comment #5
john.oltman commentedYou need to create a Relationship in Views 3 to "Content: Taxonomy terms on node". That will then open up a host of sorting possibilities within the Sort Criteria, including sorting by term name and term weight. Otherwise you are stuck sorting only by term ID, which is the order that the terms were added.
Comment #6
tj2653 commentedThanks for the explanation, John. I'm not sure if I fully understand the Relationship setup, but I was able to sort alphabetically on the terms I wanted.
Comment #7
JohnnyX commentedOk, now I can sort by weight but get duplicates... That isn't really a solution...
View is grouped by the term (=category) and now have to sorted by term weight. Any solution to do this without duplicates?
Each node have only ONE term, no multiple terms.
Comment #8
dawehnerPerhaps it helps if you provide an export which can be used by everyone.
If you have just one term per node, it would be able to work.
Comment #9
Todd Young commentedI have just one term per node, but with a hierarchy. I would like to sort in the same order as the taxonomy is arranged, which isn't by tid nor weight, and isn't straight alphabetical. Is that even possible?
Comment #10
dddbbb commentedComment #11
YourITDepartment commentedThanks, John! That was exactly what I needed. I spent hours playing around with this trying to figure it out on my own without searching for the answer. Then I stopped playing around, got serious and went to drupal.org and searched for the answer. This was the first result of the first search and your post solved my issue immediately. Thanks!
Comment #12
jnettikOk so I'm having a similar problem. I want a taxonomy grouped list of staff profiles, where the groups should be sorted by the taxonomy term weight. I added the relationship as said here, and have the proper sort criteria selected and nothing happens. Here is an export of my view:
Comment #13
wernerglinka commentedI use:
D7.10,
Views 7.x-3.1,
CTools 7.x-1.0-rc1
I am trying to do the same thing. Group a set of titles by a taxonomy term with either Semantic Views or the "native" HTML List format. I have been unsuccessful in getting the groups sorted.
I wonder whether there is anything else to consider. I have created the relationship Content: Taxonomy terms on node and the sort criteria (term) Taxonomy term: Weight (asc). The sort order stays the same, seemingly random.
To see the weight of the different terms I added (term) Taxonomy term: Weight (asc) to the fields to be displayed and all items show Weight: 0. I did modify the weight of the vocabulary items manually and they show properly on the taxonomy list page. If I add (term) Taxonomy term: Name (Name) to the fields to be displayed I get just the label: Name:
This looks like the relationship is not properly established. If I remove the relationship the sort selections for Taxonomy term: Weight is not listed anymore... just as it should be.
Comment #14
wernerglinka commentedI observed a strange thing. Without touching the view I changed all items from unpublished to published. After coming back to the Views UI all items where listed twice. One set asc and below a second set dec.
.... Views I luv ya, but your ways are mysterious...
Comment #15
peezy commentedIn case this helps someone...
I needed to add 2 relationships in order to sort my terms alphabetically:
Then, I added the sort criteria of my_field and selected the second relationship. I was unable to add the second relationship without the first one. Perhaps because my view was of user entities rather than nodes.
Comment #16
moltra commentedI have tried multiple ways of sorting my Table and still cannot get it to sort properly. It is at www.serviidb.com if anyone wants to look at it and maybe give me a clue on how to sort it.
Comment #17
Szerge commentedAfter many readings (unsuccessful but useful) and trials, I've been able to sort nodes based on the taxonomy terms used in a node!!!
1) create a relationship: Content: Taxonomy terms on node (that was well explained in different posts)
2) display a field with the taxonomy term: (term) Taxonomy term: Rendered Taxonomy term (and not the field containing the taxonomy terms with MULTIPLE FIELD SETTINGS "Display all values in the same row" unchecked !!!)
3) sort criteria: (term) Taxonomy term: Name (asc)
That's all.
With this setting, each node is displayed as many times as there are taxonomy terms associated to it, and the order is fine. No duplicate.
Comment #18
couturier commentedI think this issue may have some answers for this related problem: Duplicate rows are in the view's result set (was: distinct doesn't work)
Comment #19
couturier commentedLooks to me like this issue has been fixed for most people by the comment in #5.
For people who are experiencing other causes of duplicates, check the following:
Comment #20
fromtheindia commentedThanks, it is working fine for me.
http://drupal.org/node/1239278#comment-4858846
Comment #21
quantos commentedthanks @john.oltman. That was exactly what I needed too. Q.
Comment #22
13rac1 commentedFollow up for #5: If you've got a node with multiple single-value taxonomies:
Now grouping and Table sorting (my specific need) will work.
Comment #23
norman.loleosrei saved my day. 4,5hrs of searching and trying has an end. Thanks!
Confirming #22
Comment #24
joelhsmith commented@eosrei Is my hero-of-the-day.
Confirming #22
Comment #25
stevep commentedI had a similar problem (when attempting to sort alphabetically on taxonomy term, and getting duplicates all over the place), but achieved an easier? solution as follows:
Vocabulary name = Category(s) [note, machine name = category, as originally expected only one term per node]
Terms 1, 2, 3 etc.
nodes have multiple category terms (e.g. node 1, with Terms 2, 3, 5)
Relationships:-------------
Content: Category(s)
Configure Relationship: Content: Category(s) (field_category): Identifier =term from field_category
Require this relationship
Fields:-------------------------
Add field Content: Category(s) -- exclude from display, Formatter = link
Multiple field settings: Uncheck "Display all values in the same row"
Add additional fields as per individual need (e.g. Content: Title).
Format: ------------------
(in my case) html list
Settings:
Grouping field Nr.1 = Content: Category(s)
Check "Remove tags from rendered output "
Sort Critera: ---------------------
(first sort item) = Taxonomy term: Name (asc)
Configure sort criterion: Taxonomy term: Name
Relationship: Term from field_category
Sort asc
(second sort item) = Content: Title
sort asc
Query settings: default (distinct not set)
------------------------------------------------------------
Above provides taxomony group terms sorted alphabetically, and within each grouping, nodes are sorted alphabetically.
Summarizing: Only one relationship used. I think sorting on Taxonomy term: Name (asc) (not Content: Category(s)) is the key, as well as *requiring* the Content: Category(s) relationship. Anyway, it worked for me :)
Comment #26
Q2U commentedYikes! 5 years later -- and with Drupal 8.05 -- and John Oltman's #5 appears to have solved my duplicates issue. Thanks John! Wish I had paid attention to what you wrote when I first read your post 3 hours ago!
Comment #27
reinaldoc commented#13 worked for me
Comment #28
jenfitch commented#5 worked for me.
Comment #29
markpape commented#17 worked for me, thank you Szerge. Maybe add a point 4...
4. Lastly, ensure your "Format" settings are grouped in `Grouping field Nr.1` according to the *taxonomy term: (term) Taxonomy term: Rendered Taxonomy term*
Comment #30
timfletcher commented+1 for #5, Adding a relationship for the Taxonomy Terms on the Node, then sorting by Term Name worked for me
Comment #31
dianacastillo commented#5 worked for me on drupal 8, but i had to put no sorting at all and then it comes out in alphabetical order for the taxonomy term