0

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??

0

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
    $fields['order_id']='Totals';
    $totals->setData($fields);
    return $totals;
}

Note: Use array keys according to your grid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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