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
Comment | File | Size | Author |
---|---|---|---|
#21 | move-renders.patch | 4.3 KB | merlinofchaos |
#10 | move-renders.patch | 4.3 KB | merlinofchaos |
move-renders.patch | 4.3 KB | merlinofchaos | |
#7 | testview.export.txt | 2.63 KB | tedfordgif |
#6 | views_group-tokens_6.x-3.x-dev.patch | 4.58 KB | tedfordgif |
Comments
Comment #1
bradwade CreditAttribution: bradwade commentedMe too. I'm unsuccessfully trying to do the same type of display using Views 6.x-2.6. - Brad
Comment #2
robbertnl CreditAttribution: robbertnl commentedhave you tried select DISTINCT?
Comment #3
pam.pkrweb@gmail.com CreditAttribution: pam.pkrweb@gmail.com commentedHi
Thanks for suggest. Try Distinct to Yes. Did not work. When look at the query is puts the distinct on Node.nid.
Comment #4
tedfordgif CreditAttribution: tedfordgif commentedEdit: 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 patch2) 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 field4) Rewrite the output of that field to include the values of the other fields you need to group by (e.g. [field1] [field2])Comment #5
tedfordgif CreditAttribution: tedfordgif commentedI 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]
Comment #6
tedfordgif CreditAttribution: tedfordgif commentedHere 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])
Comment #7
tedfordgif CreditAttribution: tedfordgif commentedHere is an example view that groups on multiple fields.
Comment #8
drasgardian CreditAttribution: drasgardian commentedThanks 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.
Comment #9
tom-d CreditAttribution: tom-d commentedThanks, 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.
Comment #10
merlinofchaos CreditAttribution: merlinofchaos commentedTry 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.
Comment #12
tedfordgif CreditAttribution: tedfordgif commentedSorry 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.
Comment #13
tom-d CreditAttribution: tom-d commentedThanks 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.
Comment #14
Fr0s7 CreditAttribution: Fr0s7 commentedThe 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
Comment #15
merlinofchaos CreditAttribution: merlinofchaos commentedThe patch is against CVS and doesn't include sites/all/modules. Just apply it from the 'views' directory.
Comment #16
Fr0s7 CreditAttribution: Fr0s7 commentedI've since attempted applying the patch from the 'views' directory, but it fails to apply correctly (first of 2 hunks fails).
Comment #17
mariagwyn CreditAttribution: mariagwyn commentedI 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!
Comment #18
mariagwyn CreditAttribution: mariagwyn commentedWhile 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.
Comment #19
xjmInteresting, tracking.
Comment #20
xjmThose 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.
Comment #21
merlinofchaos CreditAttribution: merlinofchaos commentedReattaching the patch because for some reason the file itself in #12 seems to have gone walkies.
Comment #22
scottrigbyAfter 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.
Comment #23
scottrigby@merlinofchaos: is it enough to add argument 1 to line 304 in theme.inc? <? $renders = $handler->render_fields($result); ?>
Comment #24
tim.plunkettNot 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
Comment #25
merlinofchaos CreditAttribution: merlinofchaos commentedtim: That was unrelated and got its own issue anyway.
Comment #26
antiorario CreditAttribution: antiorario commentedsubscribing
Comment #27
figover CreditAttribution: figover commentedI 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.
Comment #28
merlinofchaos CreditAttribution: merlinofchaos commentedThe move-renders patch was already applied and should be a part of 2.8.
Comment #29
esmerel CreditAttribution: esmerel commentedI'm sure someone will come back and correct me if this isn't actually fixed like it appears to be.
Comment #30
dawehnerPorted this patch to d7, too.
This was missed out.
Comment #31
HJulien CreditAttribution: HJulien commentedI 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.
Comment #32
Fr0s7 CreditAttribution: Fr0s7 commentedThis 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.
Comment #33
xjm#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.