Question

By default, magento provides two options CSV and XML file format for the export.

So how can I keep one of them for export in ui component based listing ?

Was it helpful?

Solution

Add class attribute in ui_component listing xml

<exportButton name="export_button" class="Vendor\Module\Component\ExportButton">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="selectProvider" xsi:type="string">......ids</item>
        </item>
    </argument>
</exportButton>

Vendor/Module/Component/ExportButton.php

<?php
namespace Vendor\Module\Component;


class ExportButton extends \Magento\Ui\Component\ExportButton
{
    private $removeOption = 'cvs';
    /**
     * @return void
     */
    public function prepare()
    {
        $config = $this->getData('config');

        if (isset($config['options'])) {
            $options = [];
            if(isset($config['options'][$this->removeOption])) {
                unset($config['options'][$this->removeOption]);
            }

            foreach ($config['options'] as $option) {
                $option['url'] = $this->urlBuilder->getUrl($option['url']);
                $options[] = $option;
            }
            $config['options'] = $options;
            $this->setData('config', $config);
        }
        parent::prepare();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top