I have created Simple custom grid without use of UI Component.
now, i need to display total end of the columns.
anyone know how we can add total in custom grid??
I have created Simple custom grid without use of UI Component.
now, i need to display total end of the columns.
anyone know how we can add total in custom grid??
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