2

I would like my view to display just one field and additionally group by this field. So, I set the following:

  • checked "Use Aggregation" in Advanced settings
  • added the field to FIELDS section
  • in FORMAT section set the Format->Settings to group by this field
  • in FIELDS section, in Field->Aggregation chose "Group fields together"

As a result, I get the following output, assuming the field contains color values:

Blue
  Blue
  Blue
Red
  Red
  Red
  Red
Green
  Green

How to prevent displaying rows and only display group headers together with the COUNT of rows? Like this:

Blue (2)
Red (3)
Green (1)
1

I solved it. The problem with my View was that it was by default sorted by post date. Displaying the underlying SQL query showed that it selects the Post Date to be able to sort by it and that's why it displays each row.

So in this case, getting rid of detail rows means getting rid of the default sort. After that, the view displays only the Group Header row and one "Group By" row per group.

Blue
  Blue
Red
  Red
Green
  Green

To get rid of the Group Header row, hide it in CSS or in a relevant template tpl.php

In order to display the count, add the same field to the FIELDS section again, but this time with Aggregation Settings set to Count. It will look like this:

Blue
2
Red
3
Green
1

To add parenthesses, add Prefix and Suffix to the Field format. To display inline, check both fields in FORMAT->Field Settings->Display inline.

  • Why you use CSS in order to hide grouping field? There is a settings: "Exclude from display" that does it. I did not get it, sorry. – Dmytro Pastovenskyi Sep 15 '15 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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