1

I Want to Hide Export XML Option in Magento 2 Admin Grid

I only Want to Export CSV File and i am using Custom Controller for Conversion

Need Help

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing_data_source</item>
            <item name="deps" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">spinner_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">refresh</item>
                <item name="label" xsi:type="string" translate="true">Refresh Cache</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">vendor_module/product/refresh</item>
            </item>
        </item>
    </argument>
    <listingToolbar name="listing_top">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sticky" xsi:type="boolean">false</item>
            </item>
        </argument>
        <exportButton class="Magento\Ui\Component\ExportButton" component="Magento_Ui/js/grid/export" displayArea="dataGridActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="options" xsi:type="array">
                        <item name="csv" xsi:type="array">
                            <item name="visibility" xsi:type="boolean">false</item>
                            <item name="value" xsi:type="string">csv</item>
                            <item name="label" xsi:type="string" translate="true">CSV</item>
                            <item name="url" xsi:type="string">vendor_module/product/gridtocsv</item>
                        </item>
                        <item name="xml" xsi:type="array">
                            <item name="visibility" xsi:type="boolean">false</item>
                        </item>
                    </item>
                </item>
            </argument>
        </exportButton>
        <bookmark name="bookmarks"/>
        <columnsControls name="columns_controls"/>
        <massaction name="listing_massaction">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                </item>
            </argument>
            <action name="delete">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">delete</item>
                        <item name="label" xsi:type="string" translate="true">Delete</item>
                        <item name="url" xsi:type="url" path="vendor_module/product/massDelete"/>
                        <item name="confirm" xsi:type="array">
                            <item name="title" xsi:type="string" translate="true">Delete Post</item>
                            <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                        </item>
                    </item>
                </argument>
            </action>
        </massaction>
        <paging name="listing_paging">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sizesConfig" xsi:type="array">
                        <item name="component" xsi:type="string">vendor_module/js/grid/paging/sizes</item>
                    </item>
                </item>
            </argument>
        </paging>
    </listingToolbar>
    <dataSource name="vendor_module_product_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Vendor\Module\UI\DataProvider\Product\DataProvider</argument>
            <argument name="name" xsi:type="string">vendor_module_product_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">image_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">image_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="spinner_columns">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current</item>
                </item>
                <item name="editorConfig" xsi:type="array">
                    <item name="selectProvider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.spinner_columns.ids</item>
                    <item name="enabled" xsi:type="boolean">true</item>
                    <item name="indexField" xsi:type="string">image_id</item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="fieldAction" xsi:type="array">
                        <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.spinner_columns</item>
                        <item name="target" xsi:type="string">startEdit</item>
                        <item name="params" xsi:type="array">
                            <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                            <item name="1" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.listing_top.bookmarks</item>
                        <item name="root" xsi:type="string">columns.${ $.index }</item>
                        <item name="namespace" xsi:type="string">current.${ $.storageConfig.root}</item>
                    </item>
                </item>
            </item>
        </argument>
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">image_id</item>
                    <item name="component" xsi:type="string">vendor_module/js/grid/columns/multiselect</item>
                    <item name="label" xsi:type="string" translate="true">Select</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="serial_no">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">textRange</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="label" xsi:type="string" translate="true">Serial No</item>
                </item>
            </argument>
        </column>
        <column name="name" class="Vendor\Module\UI\Component\Listing\Module\Product\Column\Thumbnail">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Image</item>
                </item>
            </argument>
        </column>
        <column name="file_name">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">30</item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                    </item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Name</item>
                </item>
            </argument>
        </column>
        <column name="file_path">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">30</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                    </item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Path</item>
                </item>
            </argument>
        </column>
        <column name="added_at">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortable" xsi:type="boolean">true</item>
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">dateRange</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">40</item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Uploaded At</item>
                </item>
            </argument>
        </column>
        <actionsColumn name="actions" class="Vendor\Module\UI\Component\Listing\Module\Product\Column\Actions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">107</item>
                    <item name="indexField" xsi:type="string">image_id</item>
                </item>
            </argument>
        </actionsColumn>
    </columns>
</listing>
3

Found a solution by using custom class for export button.

<exportButton name="export_button" class="Vendor\Module\Component\ExportButton">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="options_custom" xsi:type="array">
                <item name="cvs" xsi:type="array">                    
                    <item name="value" xsi:type="string">csv</item>
                    <item name="label" xsi:type="string" translate="true">CSV</item>
                    <item name="url" xsi:type="string">vendor_module/product/gridtocsv</item>
                </item>
            </item>
        </item>
    </argument>
</exportButton>

app/code/Vendor/Module/Component/ExportButton.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Component;

/**
 * Class ExportButton
 */
class ExportButton extends \Magento\Ui\Component\ExportButton
{
    /**
     * @return void
     */
    public function prepare()
    {
        $context = $this->getContext();
        $config = $this->getData('config');
        if (isset($config['options'])) {
            $options = [];
            foreach ($config['options'] as $option) {
                /*Removed xml from here*/
                if($option['value'] != 'xml'){
                    $additionalParams = $this->getAdditionalParams($config, $context);
                    $option['url'] = $this->urlBuilder->getUrl($option['url'], $additionalParams);
                    $options[] = $option;
                }
            }
            $config['options'] = $options;
            $this->setData('config', $config);
        }
        parent::prepare();
    }
}
| improve this answer | |
  • i did this already But its not working – Waqar Ali Oct 31 '19 at 11:33
  • do you ever tried that? – Waqar Ali Oct 31 '19 at 11:33
  • Yes and working fine in my setup..Can you pls update your code? – Ranganathan Oct 31 '19 at 11:34
  • Check, is there any other exportButton tag in your file? – Ranganathan Oct 31 '19 at 11:37
  • not that is the only one – Waqar Ali Oct 31 '19 at 11:38
3

You can update your XML file with this code

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing_data_source</item>
            <item name="deps" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">spinner_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">refresh</item>
                <item name="label" xsi:type="string" translate="true">Refresh Cache</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">vendor_module/product/refresh</item>
            </item>
        </item>
    </argument>
    <listingToolbar name="listing_top">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sticky" xsi:type="boolean">false</item>
            </item>
        </argument>
        <exportButton class="Magento\Ui\Component\ExportButton" component="Magento_Ui/js/grid/export" displayArea="dataGridActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Vendor_Module/js/grid/export</item>
                    <item name="options" xsi:type="array">
                        <item name="csv" xsi:type="array">
                            <item name="visibility" xsi:type="boolean">false</item>
                            <item name="value" xsi:type="string">csv</item>
                            <item name="label" xsi:type="string" translate="true">CSV</item>
                            <item name="url" xsi:type="string">vendor_module/product/gridtocsv</item>
                        </item>
                        <item name="xml" xsi:type="array">
                            <item name="visibility" xsi:type="boolean">false</item>
                        </item>
                    </item>
                </item>
            </argument>
        </exportButton>
        <bookmark name="bookmarks"/>
        <columnsControls name="columns_controls"/>
        <massaction name="listing_massaction">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                </item>
            </argument>
            <action name="delete">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">delete</item>
                        <item name="label" xsi:type="string" translate="true">Delete</item>
                        <item name="url" xsi:type="url" path="vendor_module/product/massDelete"/>
                        <item name="confirm" xsi:type="array">
                            <item name="title" xsi:type="string" translate="true">Delete Post</item>
                            <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                        </item>
                    </item>
                </argument>
            </action>
        </massaction>
        <paging name="listing_paging">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sizesConfig" xsi:type="array">
                        <item name="component" xsi:type="string">vendor_module/js/grid/paging/sizes</item>
                    </item>
                </item>
            </argument>
        </paging>
    </listingToolbar>
    <dataSource name="vendor_module_product_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Vendor\Module\UI\DataProvider\Product\DataProvider</argument>
            <argument name="name" xsi:type="string">vendor_module_product_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">image_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">image_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="spinner_columns">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current</item>
                </item>
                <item name="editorConfig" xsi:type="array">
                    <item name="selectProvider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.spinner_columns.ids</item>
                    <item name="enabled" xsi:type="boolean">true</item>
                    <item name="indexField" xsi:type="string">image_id</item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="fieldAction" xsi:type="array">
                        <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.spinner_columns</item>
                        <item name="target" xsi:type="string">startEdit</item>
                        <item name="params" xsi:type="array">
                            <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                            <item name="1" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">vendor_module_product_listing.vendor_module_product_listing.listing_top.bookmarks</item>
                        <item name="root" xsi:type="string">columns.${ $.index }</item>
                        <item name="namespace" xsi:type="string">current.${ $.storageConfig.root}</item>
                    </item>
                </item>
            </item>
        </argument>
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">image_id</item>
                    <item name="component" xsi:type="string">vendor_module/js/grid/columns/multiselect</item>
                    <item name="label" xsi:type="string" translate="true">Select</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="serial_no">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">textRange</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="label" xsi:type="string" translate="true">Serial No</item>
                </item>
            </argument>
        </column>
        <column name="name" class="Vendor\Module\UI\Component\Listing\Module\Product\Column\Thumbnail">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Image</item>
                </item>
            </argument>
        </column>
        <column name="file_name">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">30</item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                    </item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Name</item>
                </item>
            </argument>
        </column>
        <column name="file_path">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">30</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                    </item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Path</item>
                </item>
            </argument>
        </column>
        <column name="added_at">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortable" xsi:type="boolean">true</item>
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">dateRange</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">40</item>
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">50</item>
                    <item name="altField" xsi:type="string">image_id</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Uploaded At</item>
                </item>
            </argument>
        </column>
        <actionsColumn name="actions" class="Vendor\Module\UI\Component\Listing\Module\Product\Column\Actions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">107</item>
                    <item name="indexField" xsi:type="string">image_id</item>
                </item>
            </argument>
        </actionsColumn>
    </columns>
</listing>

I've added this line

<item name="component" xsi:type="string">Vendor_Module/js/grid/export</item>

In this section..

<exportButton class="Magento\Ui\Component\ExportButton" component="Magento_Ui/js/grid/export" displayArea="dataGridActions">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="component" xsi:type="string">Vendor_Module/js/grid/export</item>
            <item name="options" xsi:type="array">
                <item name="csv" xsi:type="array">
                    <item name="visibility" xsi:type="boolean">false</item>
                    <item name="value" xsi:type="string">csv</item>
                    <item name="label" xsi:type="string" translate="true">CSV</item>
                    <item name="url" xsi:type="string">vendor_module/product/gridtocsv</item>
                </item>
                <item name="xml" xsi:type="array">
                    <item name="visibility" xsi:type="boolean">false</item>
                </item>
            </item>
        </item>
    </argument>
</exportButton>

Now you need to create one js and template file on this path..

app/code/Vendor/Module/view/adminhtml/web/js/grid/export.js

Content for this file is..

define([
    'jquery',
    'underscore',
    'uiElement'
], function ($, _, Element) {
    'use strict';

    return Element.extend({
        defaults: {
            template: 'Vendor_Module/grid/exportButton',
            selectProvider: 'ns = ${ $.ns }, index = ids',
            checked: '',
            additionalParams: [],
            modules: {
                selections: '${ $.selectProvider }'
            }
        },

        /** @inheritdoc */
        initialize: function () {
            this._super()
                .initChecked();
        },

        /** @inheritdoc */
        initConfig: function () {
            this._super();

            _.each(this.additionalParams, function (value, key) {
                key = 'additionalParams.' + key;
                this.imports[key] = value;
            }, this);

            return this;
        },

        /** @inheritdoc */
        initObservable: function () {
            this._super()
                .observe('checked');

            return this;
        },

        /**
         * Checks first option if checked not defined.
         *
         * @returns {Object}
         */
        initChecked: function () {
            if (!this.checked()) {
                this.checked(
                    this.options[0].value
                );
            }

            return this;
        },

        /**
         * Compose params object that will be added to request.
         *
         * @returns {Object}
         */
        getParams: function () {
            var selections = this.selections(),
                data = selections ? selections.getSelections() : null,
                itemsType,
                result = {};

            if (data) {
                itemsType = data.excludeMode ? 'excluded' : 'selected';
                result.filters = data.params.filters;
                result.search = data.params.search;
                result.namespace = data.params.namespace;
                result[itemsType] = data[itemsType];
                _.each(this.additionalParams, function (param, key) {
                    result[key] = param;
                });

                if (!result[itemsType].length) {
                    result[itemsType] = false;
                }
            }

            return result;
        },

        /**
         * Find checked option.
         *
         * @returns {Object}
         */
        getActiveOption: function () {
            return _.findWhere(this.options, {
                value: this.checked()
            });
        },

        /**
         * Build option url.
         *
         * @param {Object} option
         * @returns {String}
         */
        buildOptionUrl: function (option) {
            var params = this.getParams();

            if (!params) {
                return 'javascript:void(0);';
            }

            return option.url + '?' + $.param(params);
            //TODO: MAGETWO-40250
        },

        /**
         * Redirect to built option url.
         */
        applyOption: function () {
            var option = this.getActiveOption(),
                url = this.buildOptionUrl(option);

            location.href = url;

        }
    });
});

app/code/Vendor/Module/view/adminhtml/web/template/grid/exportButton.html

Content for this file is...

<div class="admin__action-dropdown-wrap admin__data-grid-action-export" collapsible>
    <button class="admin__action-dropdown" type="button" toggleCollapsible>
        <span class="admin__action-dropdown-text" translate="'Export'"/>
    </button>
    <div class="admin__action-dropdown-menu admin__data-grid-action-export-menu">
        <div class="admin__field admin__field-option" outereach="options">
            <!-- ko if: label == 'CSV' -->
                <input class="admin__control-radio" type="radio"
                    data-bind="
                        attr: {
                            id: ++ko.uid
                        },
                        checkedValue: value,
                        checked: $parent.checked"/>
                <label class="admin__field-label" text="label" attr="for: ko.uid"/>
            <!-- /ko -->
        </div>
        <div class="admin__action-dropdown-footer-main-actions">
            <button class="action-tertiary" type="button" translate="'Cancel'" closeCollapsible/>
            <button class="action-secondary" type="button" translate="'Export'" click="applyOption"/>
        </div>
    </div>
</div>

After adding above code you need to run below commands

php bin/magento setup:upgrade
php bin/magento cache:flush
php bin/magento cache:clean

Now you can see only CSV option in your backend grid.

Output :

enter image description here

Hope this will help you!

| improve this answer | |
  • But it will remove XML export option from all the grids. – Ranganathan Oct 31 '19 at 15:24
  • 1
    @Ranganathan, I've updated my code and that will only works for single grid export. :) – Kishan Savaliya Nov 1 '19 at 4:32
1

Add a class to exportButton component:

<exportButton name="export_button" class="Vendor\Module\Ui\Component\ExportButton">

And create a class which extends Magento component:


namespace Vendor\Module\Ui\Component;

class ExportButton extends \Magento\Ui\Component\ExportButton
{
    public function prepare()
    {
        $config = $this->getConfig();
        $options = $config['options'];

        if (!array_key_exists('xml', $options)) {
            parent::prepare();
            return;
        }

        unset($options['xml']);

        $config['options'] = $options;

        $this->setConfig($config);

        parent::prepare();
    }
}
| improve this answer | |

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.