8

I have created a custom grid in admin for "Seller Commission". Now, I want to show total commission earned, so need to add a row at the end of the grid which should say "Total Amount". Please help.

1 Answer 1

1

You can use renderer to show custom values or to calculate and show commission value.

For Example in your uicomponent grid xml

<column name="commission" class="Vender\Modulename\Ui\Component\Listing\Column\Commission">
    <argument name="data" xsi:type="array">        
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="sorting" xsi:type="string">asc</item>
            <item name="label" translate="true" xsi:type="string">Commission</item>
        </item>
    </argument>
</column>

And Your Renderer File

<?php

namespace Vender\Modulename\Ui\Component\Listing\Column;

class Commission extends \Magento\Ui\Component\Listing\Columns\Column {

    /**
     * @var \Magento\Directory\Api\CountryInformationAcquirerInterface
     */
    protected $countryInformation;

     /**
     * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
     * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory
     * @param array $components
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
        array $components = [],
        array $data = []
    ){
        $this->countryInformation = $countryInformation;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource) {
        if (isset($dataSource['data']['items'])) {
            $fieldName = $this->getData('name');
            foreach ($dataSource['data']['items'] as & $item) {
                //do your stuff and set value of commission in here
            }
        }

        return $dataSource;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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