如何将摘要行添加到 Drupal 视图?
我已经构建了一个视图(Drupal 6.x、Views 2.x)。我希望能够在此视图的末尾添加一个汇总行 - 对几列进行总计并将总计包含在汇总行中。
我该怎么做?我可以实现一些视图数据更改钩子来更改构造的数据(在它获得主题之前)吗?
(请注意,我无法使用 views_calc
,因为此视图中的部分数据来自视图关系,而 views_calc
在撰写本文时尚不支持该关系。)
I've built a view (Drupal 6.x, Views 2.x). I'd like to be able to add a summary row at the end of this view — total up several columns and include the totals in the summary row.
How can I do this? Is there some Views data-altering hook I can implement, to change the constructed data (before it gets themed)?
(Note that I can't use views_calc
because some of the data in this view is coming from Views Relationships, which views_calc
doesn't support at the time of writing.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
几个小时后回答我自己的问题...一种方法是实现hook_views_pre_render():
To answer my own question a couple hours later... One way would be to implement
hook_views_pre_render()
:环顾四周,看起来 Views Calc 可以做你想做的事情。
Glancing around, it looks like Views Calc can do what you want.
Views Calc 有很多未解决的错误。 View Summarize 似乎更稳定。
Views Calc has a lot of open bugs. View Summarize seems more stable.
就我个人而言,我会在视图模板中处理这个问题。为您的视图创建一个
views-view.tpl.php
,然后对其进行编辑、计算并打印出摘要。另一种选择是为同一视图创建另一个显示,然后创建一个 views-view-unformatted.tpl.php 并计算并打印出摘要,而无需执行 print $row ; 以避免调用字段模板。添加使用视图显示在需要的地方。
Personally, I would handle this in the view templates. Create a
views-view.tpl.php
for your view, and then edit it calculate and print out the summary.Another option is to create another display for the same view, and then create a
views-view-unformatted.tpl.php
and calculate and print out the summary w/o doing aprint $row;
to avoid calling the fields template. The add use view display where needed.如果其他人遇到这个问题,您可以使用 Views Summarize 添加汇总表显示。您只需设置显示,然后选择每列的汇总方式。我还无法让它与视图数据导出一起使用,但如果您只想查看网站上的数据,它就可以工作。
If anyone else comes across this question, you can use Views Summarize that adds a summarized table display. You just set the display and then choose how you want each column summarized. I haven't been able to get this to work with Views Data Export yet, but it works if you just want to see the data on the site.