本文介绍了在奏鸣曲管理列表的顶部显示订单总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

筛选特定条件后,在页面顶部显示销售交易总额.如果页面多于一页,这应该是所有页面的总和.

谁能指导我如何做到这一点

解决方案

我们按照以下方式做到了,而且效果很好

第一步:在orderAdmin中添加两个方法

公共函数getTemplate($name){if($name == 'list') {返回 '​​AppBundle:OrderAdmin:list.html.twig';}return parent::getTemplate($name);存根}公共函数 getSumOf($field){$datagrid = $this->getDatagrid();$datagrid->buildPager();$query = $datagrid->getQuery();$query->select('SUM(' . $query->getRootAlias() . '.' . $field . ') as total');$query->setFirstResult(null);$query->setMaxResults(null);$result = $query->execute(array(), \Doctrine\ORM\Query::HYDRATE_SINGLE_SCALAR);返回 $result;}

第 2 步:创建模板文件 list.html.twig

{% 扩展 'SonataAdminBundle:CRUD:base_list.html.twig' %}{% 阻止 list_header %}<div class="pull-right" style="margin-right: 10px;"><label for="{{ admin.uniqid }}_sum_of_orders" class="control-label">总计:</label><label class="control-label">S$ {{ admin.getSumOf('orderAmount') }} </label>

{% 结束块 %}

After filtering for a particular criteria, display total of the sales transaction amounts on top of the page. This should be total of all the pages if pages are more than one.

Can someone guide me how to do this

解决方案

We did it in the following manner and it is working like a charm

Step 1 : Added two methods in orderAdmin

public function getTemplate($name)
{
    if($name == 'list') {
        return 'AppBundle:OrderAdmin:list.html.twig';
    }

    return parent::getTemplate($name); stub
}

public function getSumOf($field)
{
    $datagrid = $this->getDatagrid();
    $datagrid->buildPager();
    $query = $datagrid->getQuery();

    $query->select('SUM( ' . $query->getRootAlias() . '.' . $field . ') as total');
    $query->setFirstResult(null);
    $query->setMaxResults(null);


    $result = $query->execute(array(), \Doctrine\ORM\Query::HYDRATE_SINGLE_SCALAR);

    return $result;
}

Step 2: Created a template file list.html.twig

{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}
{% block list_header %}
<div class="pull-right" style="margin-right: 10px;">
    <label for="{{ admin.uniqid }}_sum_of_orders" class="control-label">Grand Total: </label>
    <label class="control-label"> S$ {{ admin.getSumOf('orderAmount') }} </label>
</div>
{% endblock %}

这篇关于在奏鸣曲管理列表的顶部显示订单总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 13:17