Note: I am not using ui component to create my grid

I want to show totals at the end of the grid: enter image description here

I got stack exchange question related to this, but its for Magento 1.9

How to add a column Total row in a magento grid at the end

Can anyone would help me on this?

1 Answer 1


In Grid.php file added a protected variable on class level

protected $_countTotals = true;

then add a function

public function getTotals()
    $totals = new \Magento\Framework\DataObject;
    $fields = array(
        'sold_count' => 0,
        'unit_price' => 0,
        'total_amount' => 0
    foreach ($this->getCollection() as $item) {
        foreach($fields as $field=>$value){
            if($field == "position" || $field == "total_limit") {
                $fields[$field] += $item->getData($field);
    //First column in the grid
    return $totals;

I hope this will help

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.