简体   繁体   English

SonataAdminBundle如何在列表视图中对列的值求和

[英]SonataAdminBundle how to sum values of a column in the list view

I've a Symfony 2.8 project where I'm using SonataAdminBundle for basic CRUD of working hours. 我有一个Symfony 2.8项目,我正在使用SonataAdminBundle进行工作时间的基本CRUD。 In the main list view (defined with configureListFields(ListMapper $listMapper) ) there's a column with hours value that I want to sum and show in the footer of the list's table. 在主列表视图中(使用configureListFields(ListMapper $listMapper)定义),有一个带有小时值的列,我希望求和并显示在列表表格的页脚中。

What's the best way to achieve this? 实现这一目标的最佳方法是什么? How can I access the collection shown from the Twig template in order to iterate over all elements and sum the right values? 如何访问Twig模板中显示的集合,以迭代所有元素并总结正确的值?

How can I access the collection shown from the Twig template in order to iterate over all elements and sum the right values? 如何访问Twig模板中显示的集合,以迭代所有元素并总结正确的值?

If you're suggesting doing that in the template, I think you shouldn't, if you're suggesting doing that in the controller with php, I think you shouldn't either. 如果你建议在模板中这样做,我认为你不应该,如果你建议用控制器用php做这个,我想你也不应该。 I think you should get the DQL query corresponding to the list from the pager, clone it and modify it to add a call to the SUM() SQL function, the executing and inject the result in your template. 我认为您应该从寻呼机获取与列表对应的DQL查询,克隆并修改它以添加对SUM() SQL函数的调用,执行并将结果注入模板中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM