Ok, I have a view where I am pulling in fields (rows style fields) as child and parent, and need to group by parent node title and body where the parent can have multiple children. I currently group by Parent node title but the parent node body is showing for each child when only want it once. Is there away to do this just within views? I would think grouping on multiple fields would be a common function used and need.

Example on what getting:
Parent Node 1 Title
Parent Node 1 body
child info
Parent node 1 body
child info
Parent node 1 body
child info
Parent Node 2 title
Parent Node 2 body
child info
Parent Node 2 body
child info

Example of what I want
Parent Node 1 Title
Parent Node 1 body
child info
child info
child info
Parent Node 2 title
Parent Node 2 body
child info
child info

Any help or suggestions would be great. I have been researching for several days with no lucky.
Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bradwade’s picture

Me too. I'm unsuccessfully trying to do the same type of display using Views 6.x-2.6. - Brad

robbertnl’s picture

have you tried select DISTINCT?

pam.pkrweb@gmail.com’s picture

Hi

Thanks for suggest. Try Distinct to Yes. Did not work. When look at the query is puts the distinct on Node.nid.

tedfordgif’s picture

Status: Needs review » Active
FileSize
4.67 KB

Edit: don't use this patch--I'll resubmit a corrected version in a few days.

The attached patch allows you to group on multiple fields using the Fields row style.
1) Apply the patch
2) Add all the fields you need to group by, and hide them.
3) On the style settings, select the last field you want to group by as the grouping field
4) Rewrite the output of that field to include the values of the other fields you need to group by (e.g. [field1] [field2])

tedfordgif’s picture

Status: Active » Needs review

I should have mentioned that this patch is against 6.x-2.x-dev of 7/2/2009.

Further explanation: the patch moves the grouping routine into the main rendering loop. This allows using tokens for other fields to rewrite the output of the field. It's a fairly simple patch, but unfortunately diff makes it look more complex than it is.

Also, I removed the h3 tags from theme/views-view-{list,unformatted}.tpl.php, since it is too much of an assumption that the end user will want an h3 there. If you need to add tags around one of the field values, just rewrite the output of that field:

<h3>[field1]</h3> [field2]

tedfordgif’s picture

Status: Active » Needs review
FileSize
4.58 KB

Here is the proper patch, which allows you to group on multiple fields using the Fields row style. It is against 6.x-3.x-dev, but also applies cleanly to -2.x-dev, and -2.6.

1) Apply the patch
2) Add all the fields you need to group by, and hide them.
3) On the style settings, select the last field you want to group by as the grouping field
4) Rewrite the output of that field to include the values of the other fields you need to group by (e.g. [field1] [field2])

tedfordgif’s picture

FileSize
2.63 KB

Here is an example view that groups on multiple fields.

drasgardian’s picture

Thanks for the good work on that patch, it applied ok for me however it broke the use of grouping fields on any table style views. - Grouping field output simply doesn't display.

tom-d’s picture

Thanks, I had been looking for this for a long time.

What happened to the table style? I can't work out why it doesn't work anymore.

merlinofchaos’s picture

FileSize
4.3 KB

Try this patch instead. It moves the whole field rendering process earlier which will simplify things for styles as well. I don't think it impacts existing styles, except that they'll duplicate rendering until they're updated.

tedfordgif’s picture

Sorry for taking so long to get back to you all...The table style stopped working because I removed a method (thinking it was not used elsewhere...bad assumption). I haven't had time to rework the patch yet, but hopefully I'll have time to do that soon.

tom-d’s picture

Thanks tedfordgif and merlinofchaos

I tried the patch move-renders.patch which works fine except I get a warning message

warning: Missing argument 1 for views_plugin_style::render_fields(), called in /modules/views-HEAD/theme/theme.inc on line 304 and defined in/modules/views-HEAD/plugins/views_plugin_style.inc on line 217.

I have tried to have a quick look at whats wrong but my experience is limited.

Fr0s7’s picture

The patch doesn't seem to install correctly on Acquia Drupal, because the Views module is located in:

modules/acquia/views

rather than:

sites/all/modules/views

merlinofchaos’s picture

The patch is against CVS and doesn't include sites/all/modules. Just apply it from the 'views' directory.

Fr0s7’s picture

I've since attempted applying the patch from the 'views' directory, but it fails to apply correctly (first of 2 hunks fails).

mariagwyn’s picture

I applied the move-renders (@Fr0st: from within the views folder - might explain the failure), and it applied. I did get an odd report, "patch unexpectedly ends in middle of line." However, it solved the problem of applying field tokens and rewrites to HTML fields (http://drupal.org/node/484686).

Merlin: I am regularly grateful for your prompt responses to views and panels issues. If you are ever in portland, or, I would be delighted to buy you a beer!

mariagwyn’s picture

While the patch works to fix the problem, I also am getting the same error as #13:

warning: Missing argument 1 for views_plugin_style::render_fields(), called in .../public_html/sites/all/modules/views/theme/theme.inc on line 304 and defined in .../public_html/sites/all/modules/views/plugins/views_plugin_style.inc on line 217.

I thought it might have to do with the "group by" function, and turned it off in one view, but error still appears. None of the handlers in the view itself register anything missing.

xjm’s picture

Interesting, tracking.

xjm’s picture

Version: 6.x-2.5 » 6.x-2.x-dev

Those who are having problems applying the patch, note that it is against the current dev build; applying it against 2.5 or 2.6 will fail. mariagwyn's error sounds like it may be due to the 2nd chunk of the patch failing.

Patch in #10 applied for me with no errors and has the desired effect.

merlinofchaos’s picture

FileSize
4.3 KB

Reattaching the patch because for some reason the file itself in #12 seems to have gone walkies.

scottrigby’s picture

Status: Needs review » Active

After IRC with merlinofchaos, i see the patch has already been applied to lastest dev (so marking 'active' since there's no patch).

I enabled that on a clean D6.14 install, and although the grouping *does work* (yay) -- i however still get the exact same error as #18.

scottrigby’s picture

@merlinofchaos: is it enough to add argument 1 to line 304 in theme.inc? <? $renders = $handler->render_fields($result); ?>

tim.plunkett’s picture

Not sure if this is the issue that resulted in this commit (http://drupal.org/cvs?commit=280734), but the $grouping = url($grouping) caused the span tag to become unescaped.

It now reads
%3Cspan%20class%3D%22date-display-single%22%3EWednesday%2C%2010/28/09%3C/span%3E
Where it should read
Wednesday, 10/28/09

merlinofchaos’s picture

tim: That was unrelated and got its own issue anyway.

antiorario’s picture

subscribing

figover’s picture

I tried to attach this patch. I downloaded fresh views module from here http://ftp.drupal.org/files/projects/views-6.x-2.8.tar.gz

copied this patch with the name move-renders_1.patch at sites/all/modules/views directory.

Then i login within cygwin and cd c:/wamp/www/drupal.test.me/htdocs/sites/all/modules/views

and then applied this patch command "patch -p0 < move-renders_1.patch"

But i am watching this error.
"
$ patch -p0 < move-renders_1.patch
patching file plugins/views_plugin_style.inc
Hunk #1 FAILED at 183.
Hunk #2 succeeded at 251 with fuzz 1 (offset 43 lines).
1 out of 2 hunks FAILED -- saving rejects to file plugins/views_plugin_style.inc
.rej
patching file theme/theme.inc
Reversed (or previously applied) patch detected! Assume -R? [n]
"
I think, i am doing some thing fundamently wrong, but not sure about it. Please guide me about it.

merlinofchaos’s picture

The move-renders patch was already applied and should be a part of 2.8.

esmerel’s picture

Status: Active » Closed (fixed)

I'm sure someone will come back and correct me if this isn't actually fixed like it appears to be.

dawehner’s picture

Ported this patch to d7, too.
This was missed out.

HJulien’s picture

I could not get this to work. It seems I've tried every combination of views settings including those listed above. I've tried grouping by hierarchy and/or depth. I've tried grid, table, etc. The closest I can get is to have the list in the right order. I have taxonomy lineage installed and hoped that between the two of them I'd be able to do it. I'm using Views 6.x -2.12 which I think already has all of the patched included.

What I'd like best would be to have a table like this:

Parent1 Parent 2 Parent 3 Parent 4 Parent 5
--Child1a --Child2a --Child3a --Child4a --Child5a
--Child1b --Child2b --Child3b --Child4b
--Child1c --Child2c --Child4c

Adding php code is fine as long as it's really clear what goes where. If anyone has figured out how to do this, I'd love to know.

Fr0s7’s picture

This is a complicated query to display. I have not been able to use the patches above with any success, but I was able to accomplish what I needed via some heavy PHP in the Views templates (theme layer). It was so much PHP, however, that it really should have been a module. I do have plans to write such a module as a Views Display Plugin, but I'm mostly a Themer, and have no idea how to write modules. This will be my first project. I'll comment back here when I've learned what I'm doing.

xjm’s picture

#31: If you're having issues with lineage, please open an issue in the lineage queue. However, at present, lineage only supports nested lists (not tables). You'd have to write your own plugin for a table.