1

How to display total row at the end of sales order grid.see below image

enter image description here

0

1 Answer 1

4

source How to add a Total row in a magento grid

thanks to @mazeUz

first you have override sales/grid.php

then if you want to add total row then add below code

class SSD_Uzkart_Block_Adminhtml_Uzkart_Grid 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
     */

}

[EDIT]

if it display check box rather then label Total then you have to first check it must match with first column grid id if it's your increment_id then it must be

$fields['increment_id']='Totals';

IMage

8
  • I have changed to 'increment_id' but still it display checkbox.
    – Zahirabbas
    Commented Feb 17, 2014 at 8:38
  • @Freedom not increment_id you have to set first column id. is increment_id your first column?
    – Keyur Shah
    Commented Feb 17, 2014 at 8:40
  • $this->addColumn('real_order_id', array( 'header'=> Mage::helper('sales')->__('Order #'), 'width' => '80px', 'type' => 'text', 'index' => 'increment_id', )); First column
    – Zahirabbas
    Commented Feb 17, 2014 at 8:41
  • when i changed to 'real_order_id' it's doesn't display Totals label
    – Zahirabbas
    Commented Feb 17, 2014 at 8:44
  • is increment_id your first column ?
    – Keyur Shah
    Commented Feb 17, 2014 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.