码迷,mamicode.com
首页 > 其他好文 > 详细

How to add a Total row in a magento grid

时间:2015-09-14 17:00:12      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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
技术分享

How to add a Total row in a magento grid

标签:

原文地址:http://my.oschina.net/liufeng815/blog/505926

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!