Magento2 – How to Add Export Functionality in New Grid System

exportgridmagento2

In Magento 1 I could add export functionality to any admin grid I create by adding this

$this->addExportType('*/*/exportCsv', Mage::helper('helper_alias')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('helper_alias')->__('Excel XML'));

in the _prepareColumns of the grid block and then implementing the expotCsvAction and exportXmlAction in my admin controller.

How can I achieve the same result in Magento 2 in the new grid system? (the one that uses ui components and knockout js for rendering). Example, the products grid, the cms pages grid.
Or better yet, is this even possible?

Best Answer

You can use sales/orders grid as example.

exportButton ui component responsable for UI

       <exportButton name="export_button">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="selectProvider" xsi:type="string">sales_order_grid.sales_order_grid.sales_order_columns.ids</item>
                </item>
            </argument>
        </exportButton>

where selectProvider is component responsible for selections data.

By default csv/xml options available and leads to \Magento\Ui\Controller\Adminhtml\Export\GridTo{Csv,Xml} action that export all selected data from data provider.