0Day Forums
Drupal: Views: grouping relationship in block list - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: CMS (https://zeroday.vip/Forum-CMS)
+---- Forum: Drupal (https://zeroday.vip/Forum-Drupal)
+---- Thread: Drupal: Views: grouping relationship in block list (/Thread-Drupal-Views-grouping-relationship-in-block-list)



Drupal: Views: grouping relationship in block list - unfounded51 - 07-26-2023

I have a question about views, specifically about grouping a relationship. I have a "partner" node that has many "docs", I want to list the name of the "partner" along with its corresponding "docs" below. I have the relationship set up correctly(I think) but can't figure out how or where to group it correctly.

I get this:

partner name 1
- doc name 1
partner name 1
- doc name 2
partner name 1
- doc name 3
partner name 2
- doc name 4
partner name 2
- doc name 5
partner name 3
- doc name 6

but would like this:

partner name 1
- doc name 1
- doc name 2
- doc name 3

partner name 2
- doc name 4
- doc name 5
- doc name 6


RE: Drupal: Views: grouping relationship in block list - loranbzb - 07-27-2023

It sounds like you're on the right track. In order to get the grouping to work as you outline above, you'll need to set the display style to 'html list', and then under the style options, set the grouping field to the partner name. Once you have this working, you can edit the partner name field, and select 'exclude from display', which should then give you the desired format.


RE: Drupal: Views: grouping relationship in block list - pape780 - 07-27-2023

I ran into this same problem today. In an attempt to troubleshoot, I made a new empty installation of Drupal and added only my content type and the relationship. When I created the view I did not see the problem. Once I started adding modules back in I found that the theme developer in the development module is causing the problem. Try unchecking it and reloading your view. You might also be able to see this by leaving the item checked, opening up a different browser and going to the view as someone that will not see the theme developer.


RE: Drupal: Views: grouping relationship in block list - Mrperegrinegkynqzzs - 07-27-2023

I have had some success using the [views_field_view][1] module which allows you to specify a view as a field.

First I created a view with the single field that I wanted to group by and then over-rode the query using the following code.

function hook_views_pre_execute(&$view) {
if ($view->name == 'phone_search') {
$query = 'SELECT DISTINCT node_data_field_status.field_status_value AS node_data_field_status_field_status_value
FROM content_type_phone node_data_field_status';
$view->query->query = $query;
$view->query->final_query = $query;
$view->query->count_query = $query;
}
}
The reason for this is that views automatically includes the `nid` and the `vid` fields when you have it set to select distinct so you don't actually get the distinct values. By hacking the query like this I worked around this issue.

The `views_field_view` module allowed me to create a second view with the fields that I wanted to be shown in the groups. When you add the view_field to the primary view (the one that the query is over-ridden in) you can specify a field to pass in as an argument. This argument must then be specified in the child view.

It all is a bit complicated but I hope this was clear!


[1]:

[To see links please register here]




RE: Drupal: Views: grouping relationship in block list - miniseries13473 - 07-27-2023

This is something views is weak at.

I usually write a module to produce these kinds of results as I find writing sql to quicker and more maintainable than wrestling with views to do it.

That said, there are many views plugins out there that offer this type of functionality. I have not tested them because I find this easier handled with a small amount of custom code in general, but here are a few projects seeking to provide a solution to this type of thing for views.

[To see links please register here]


[To see links please register here]


There are many others, but I can only post two links because I don't often answer questions on this site :)

cheers