0

This is my custom admin grid.

enter image description here

The last column shows the total which is a multiplication of cost and qty fields. I want to show total of the column(total) in the last row and last column.

The row total is rendered through this function:


class Total extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{    /**
     * Renders grid column
     *
     * @param   Varien_Object $row
     * @return  string
     */
    public function render(\Magento\Framework\DataObject $row)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
        $total_revenue_amount = 0;
        $total_qty = $row->getData("total_qty");
        $price = $row->getData("cost");
        // if(!empty($total_qty) && !empty($price)){
        //     $total_revenue_amount = $total_qty*$price;
        // }
        
        if(count($row->getData()) > 4){
            if(!empty($total_qty) && !empty($price)){
                $total_revenue_amount = $total_qty*$price;
            }
        }else{
            $total_revenue_amount = $row->getData('total_revenue_amount');
        }
        return $priceHelper->currency($total_revenue_amount, true, false);
    }
}



Any help will be appreciated.

0

1 Answer 1

0

I find a solution. I hope this can help you.

Find the row in your ui component js file where is write the item tag with name "component":

<argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
        </item>
    </argument>

and change it like:

<argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">YourVendor_YourModule/js/grid/provider</item>
        </item>
    </argument>

The path of that js file is:

vendor/magento/module-ui/view/base/web/js/grid/provider.js

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.