How to add a Total row in a magento grid

add these fields to your gird class

class *** extends Mage_Adminhtml_Block_Widget_Grid
{
    protected $_countTotals = true;

    public function getTotals()
    {
        $totals = new Varien_Object();
        $fields = array(
            ‘uzkart_trans_amount‘ => 0, //actual column index, see _prepareColumns()
            ‘some_summarable_field‘ => 0,
            ‘another_countable_field‘ => 0,
        );
        foreach ($this->getCollection() as $item) {
            foreach($fields as $field=>$value){
                $fields[$field]+=$item->getData($field);
            }
        }
        //First column in the grid
        $fields[‘entity_id‘]=‘Totals‘;
        $totals->setData($fields);
        return $totals;
    }

    protected function _prepareColumns()
    {
        /**
         * another columns
         */

        $this->addColumn(‘uzkart_trans_amount‘, array(
            ‘header‘ => Mage::helper(‘uzkart‘)->__(‘Payment Amount‘),
            ‘index‘ => ‘uzkart_trans_amount‘,
            ‘type‘ => ‘currency‘,
        ));

        /**
         * another columns
         */
    }

    /**
     * another methods
     */

}

but have other question

Hide the Action Column in totals and more

add ‘totals_label‘ => ‘‘ in your action column

时间: 2024-08-17 01:25:19

How to add a Total row in a magento grid的相关文章

【02_258】Add Digits

Add Digits Total Accepted: 49702 Total Submissions: 104483 Difficulty: Easy Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2.

leetcode_67题——Add Binary(字符串string,反向迭代器reverse_iterator,栈stack)

Add Binary Total Accepted: 39288 Total Submissions: 158078My Submissions Question Solution Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". Hide Tags Math String Have

leetcode_241——Different Ways to Add Parentheses (递归,动态规划)

Different Ways to Add Parentheses Total Accepted: 1708 Total Submissions: 6304My Submissions Question Solution Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and op

FunDA(16)- 示范:整合并行运算 - total parallelism solution

在对上两篇讨论中我们介绍了并行运算的两种体现方式:并行构建数据源及并行运算用户自定义函数.我们分别对这两部分进行了示范.本篇我准备示范把这两种情况集成一体的并行运算模式.这次介绍的数据源并行构建方式也与前面描述的有所不同:在前面讨论里我们预知需要从三个独立流来并行构建数据源.但如果我们有一个不知长度的数据流,它的每个元素代表不同的数据流,应该如何处理.我们知道在AQMRPT表里有从1999年到2xxx年的空气质量测量数据,我们可以试着并行把按年份生成的数据流构建成一个数据源.直接使用上期示范中的

Leetcode 数 Add Binary

本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Add Binary Total Accepted: 9509 Total Submissions: 37699 Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 题意:

[转]How to insert a row between two rows in an existing excel with HSSF (Apache POI)

本文转自:http://stackoverflow.com/questions/5785724/how-to-insert-a-row-between-two-rows-in-an-existing-excel-with-hssf-apache-poi Somehow I manage to create new rows between two rows in an existing excel file. The problem is, some of the formatting were

DataSet中compute的使用

在为筛选器创建表达式时,用单引号将字符串括起来: "LastName = 'Jones'" 下面的字符是特殊字符,如下面所解释的,如果它们用于列名称中,就必须进行转义: \n (newline) \t (tab) \r (carriage return) ~ ( ) # \ / = > < + - * % & | ^ ' " [ ] 如果列名称包含上面的字符之一,该名称必须用中括号括起来.例如,若要在表达式中使用名为“Column#”的列,应写成“[Col

算法之美_源代码发布(5)

本文辑录了<算法之美--隐匿在数据结构背后的语言>(电子工业出版社2016年出版)一书第5~6章之代码(P149~P183).全文目录."45个算法"目录."22个经典问题目录",以及有奖捉虫活动详情请见如下链接:http://blog.csdn.net/baimafujinji/article/details/50484348 附录中的经典笔试.面试问题参考答案请见: http://blog.csdn.net/baimafujinji/article/

C Primer Plus_第10章_数组和指针_编程练习

1. /*rain.c 针对若干年的降水量数据,计算年降水总量.年降水平均量,以及月降水平均量*/ #include <stdio.h> #define MONTHS 12 #define YEARS 5 int main (void) { //把数组初始化为2000到2004年的降水量数据 const float rain[YEARS][MONTHS] = //const声明和初始化数组可保护数据 { {4.3, 4.3, 4.3, 3.0, 2.0, 1.2, 0.2, 0.2, 0.4,