I have created Simple custom grid without use of UI Component.

now, i need to display total end of the columns.

enter image description here

anyone know how we can add total in custom grid??


1 Answer 1


Add a class level variable $_countTotals and set value true

protected $_countTotals = true;

And add function

public function getTotals()
    $totals = new \Magento\Framework\DataObject;
    $fields = array(
        'total' => 0,
        'total_weight' => 0,
        'carrier_price' => 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;

Note: Use array keys according to your grid

  • this solution is not working.
    – Himanshu
    Commented Aug 28, 2023 at 5:34

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.