Posted by DanZ on January 21, 2013 at 4:05am
I have multiple Views to put on a page. They are different reports, but all of them need an input: A single date range, (for which I'm using an exposed filter). I don't want the user to enter the same date range multiple times on the same page.
What's a clean way to do this?
I can program a module if it comes to that.
Solution: Make one display of the first view a page with the exposed filter inputs. Make more displays of that view as Attachment displays, attached to the Page display. Turn on "Inherit exposed filters" in the attachments. Make sure the exposed filters are the same, and otherwise customize the attachments to display their own information.
Easy, and works great.
Comments
Use panels?
Interesting question. Some thoughts...
1)
If you had the date range, I suppose you might be able to use panels and have each view in a separate panel. You would then 'just' have to have a form with for the input ranges.
2) You could perhaps build up the content for each view in the template preprocessing and then embed,
e.g.
I have embedded a view in a template before:
<?phpMYTHEME_preprocess_node(&$variables, $hook) {
if ($node->type == "community") {
$variables['community_projects'] = views_embed_view('community_projects', 'default', $variables['node']->nid);
}
?>
and then embedded this variable in my node--community.tpl (the template for the community node type).
<?phpprint $community_projects;
?>
drupalshrek
Maintainer of the VChess module visible in use at chess website Chesspos.com
Sorry, I know very little
Sorry, I know very little about Panels so far.
Aren't they just convenient ways of arranging content into Blocks? Views can already be Blocks. Why put each View into a separate Panel?
The Panels docs mention something called Contexts. Could that be used to provide input to Views?
Views have something called Contextual Filters, which have something to do with taking arguments from a the URL. Would that be useful?
There's a module called Webforms which sets up forms. Would it be possible to set up a Webform on a page which would allow the user to enter a date range, then have the Webform submission go to a URI with the date range? Then, could this somehow be picked up as contextual filters for a series of Views in a Panel?
--
www.ztwistbooks.com. Math books that are actually fun.
attachment
This is pretty straightforward to do and you don't need to write any code.
In your view, make the top view a Page Display and include the exposed filter. Then, for each subsequent view, make an Attachment Display and under Attachment Settings, set Inherit Exposed Filters to YES.
You can have as many Attachment Displays as you need, but do plan them out first and create them in the order in which you want them to appear on the page. I haven't figured out how to rearrange them once they've been created.
I should add that this method
I should add that this method does not require Panels or any work at the theme layer.
Ah, yes. That's the way to
Ah, yes. That's the way to do it. I didn't know about attached views. Thank you! They are new displays that can attach to an existing display.
I've tried this, and can attach new tables, but two things are not yet working:
First, aggregation does not appear to be working properly for the attached views. As soon as I add a new field with GROUP BY on it, there's no aggregation. Aggregation does work on that field in an independent View. It also works for SUM() (not group-by). Is that a bug, or am I doing something wrong?
Second, the additional tables from the attached views do not have any sort of titles on them. Is there a way to add those so it's more obvious what's in the different tables?
--
www.ztwistbooks.com. Math books that are actually fun.
The GROUP-BY was broken from
The GROUP-BY was broken from using a bad relationship.
The way to add the title is to add a header and type some HTML.
As for re-arranging the attached displays, there seem to be a "Reorder displays" menu item under "edit view name/description". That should do it.
--
www.ztwistbooks.com. Math books that are actually fun.
I would not use panels, this
I would not use panels, this sounds a bit dynamic, and panels is super super heavy. This also sounds like a node TPL. What I like to do with my views is embed them into the node TPL. I either have a ton of control over the argument, which saves complex argument validation sometimes, or know it's coming from the URL.
I would stick to embedding them into my TPL (node--type.tpl.php) with views_embed_view...or use the Context module to place them in sidebars.
At this point....with how heavy D7 is database wise, I would steer clear of panels....with context and delta and themes like Omega panels has become too much.
------------
Custom Drupal development and theming. http://www.drewbolles.com