0

I have a field in the View called Dealer Name. Dealer Name is populated from a list that looks like this:

#111 | Dealer 1
#112 | Dealer 3
#113 | Dealer 3

I need this field to be Alphabetically Sortable but when I apply sortable it sorts on the ID. What befuzzles me is that in the HTML only the Name is printed not the ID so how does it know to sort on the ID? (see below)

<td class="views-field views-field-field-da-dealer">
    Dealer Name
</td>

How can I change this behaviour to sort on the Name?

5
  • What does the sort area in the View say currently?
    – Laryn
    Oct 20, 2014 at 22:05
  • Content: Post Date I think you have pointed me to the right place :) Oct 20, 2014 at 22:10
  • Unfortunately that didn't get me any further. If you have any pearls of wisdom, please share! Oct 20, 2014 at 22:20
  • Ah. I'll see if I can type something up.
    – Laryn
    Oct 20, 2014 at 22:21
  • Part of the problem is caused by using a list of text items. Rather use taxonomy terms. That way you can add new terms later on. AFAIK, when using a list you cannot add new items without deleting the field and recreating it. Oct 21, 2014 at 6:32

4 Answers 4

0

When you edit your view, you should see "Sort Criteria" at the bottom of the left column. I think it defaults to "Updated date". If anything is in this section, you'll probably want to delete it and then click on "Add" to pick the id as your real sort criterion.

0

It sounds like the view is sorting on Post Date currently (as pictured below), so you will need to edit the view, and in the sort criteria section, click "Add" to add the "DA Dealer" field. Then you need to remove the "Post Date" sort item, which you can do by clicking on the small downward arrow beside the "Add" link and choose "Rearrange" in the dropdown that appears -- this will allow you to rearrange or delete the sort criteria.

enter image description here

8
  • Tx I tried that but it didn't change the behaviour at all. I flushed cache too. Currently under Sort Criteria I have Content: Dealer Name (asc) - This is the field in question and Content: Title (asc) Oct 20, 2014 at 22:37
  • Did you create this view? (e.g. I'm curious if there is any rewriting on that Dealer Name field, or if the view in question has multiple displays it's possible you are editing/looking at the wrong display.)
    – Laryn
    Oct 20, 2014 at 22:40
  • I didn't create the view but I'm pretty sure it's the right view. I can see the correct preview below the View Oct 20, 2014 at 22:42
  • In the "Fields" area (2 sections above "Sort Criteria") click on the "Dealer Name" field and in the "Rewrite Results" section, let me know if the box is checked for "Rewrite the output of this field".
    – Laryn
    Oct 20, 2014 at 22:47
  • It is not checked Oct 20, 2014 at 22:48
0

To answer the "why?" part of your question:

Drupal Views sorts the contents of your view long before constructing the HTML for it, so it does not need the id within the HTML to know which order to put it in.

As for "how can I fix it?"...

I think Laryn is on the right track. Are you using any plugins for Views? I have found some in the past that get the sorting wrong, notably Pivot Tables for Views.

1
  • Tx for the info and no plugins for sorting are being used. Oct 20, 2014 at 22:46
0

In the end I had to use a hack to get the Dealer Name field to be sortable alphabetically. The Title field was working so I used Rewrite Results on that to display the info from Dealer Name. It isn't an ideal solution but it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.