0

I am using Ui-Component for export button for export grid column with below code:

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

Anyone have faced this kind of issue... Please let me know if i need to post my Dataprovider class

My collection file is below:

class Collection extends TestCollection implements SearchResultInterface
{
     /**
     * {@inheritdoc}
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

    /**
     * {@inheritdoc}
     */
    public function setAggregations($aggregations)
    {
        $this->aggregations = $aggregations;
    }

    /**
     * {@inheritdoc}
     */
    public function getSearchCriteria()
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
    {
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getTotalCount()
    {
        return $this->getSize();
    }

    /**
     * {@inheritdoc}
     */
    public function setTotalCount($totalCount)
    {
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setItems(array $items = null)
    {
        return $this;
    }
}

Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Ui\Model\Export\MetadataProvider::getRowData() must be an instance of Magento\Framework\Api\Search\DocumentInterface, instance of Package\Module\Model\Test given, called in /home/ashish/magentoPro/vendor/magento/module-ui/Model/Export/ConvertToCsv.php on line 84 and defined in /home/ashish/magentoPro/vendor/magento/module-ui/Model/Export/MetadataProvider.php:147 ...

2

I have resolved the issue by adding below code

$this->_init(
      'Magento\Framework\View\Element\UiComponent\DataProvider\Document', 'Package\Module\Model\ResourceModel\Test'
            );

to my Grid Collection file(path:Package\Module\Model\ResourceModel\Test\Grid\Collection):

Full Code:

    class Collection extends TestCollection implements SearchResultInterface
    {
        /**
         * Define model & resource model
         */
         protected function _construct() {
             $this->_init(
                        'Magento\Framework\View\Element\UiComponent\DataProvider\Document', 'Package\Module\Model\ResourceModel\Test'
             );
         }
     /**
     * {@inheritdoc}
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

    /**
     * {@inheritdoc}
     */
    public function setAggregations($aggregations)
    {
        $this->aggregations = $aggregations;
    }

    /**
     * {@inheritdoc}
     */
    public function getSearchCriteria()
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
    {
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getTotalCount()
    {
        return $this->getSize();
    }

    /**
     * {@inheritdoc}
     */
    public function setTotalCount($totalCount)
    {
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setItems(array $items = null)
    {
        return $this;
    }
}

As the error was indicating I need to pass Magento\Framework\View\Element\UiComponent\DataProvider\Document as a model for the Grid document for getItems() abstarct function of SearchResultInterface So that the Grid export default functionality can work and it is working like charm.

Anyone facing this kind of issue can let me know I will share my experience.

Thanks

  • 1
    Thanks, worked for me! To clarify it should be added here: Package\Module\Model\ResourceModel\Test\Grid – Mehdi Dec 7 '17 at 17:19
  • I have tried to implement export option in the product grid. When try to enable the export button from product_listing.xml, I'm facing the following issue while export Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Ui\Model\Export\ConvertToXml::getRowData() must be an instance of Magento\Framework\Api\Search\DocumentInterface, instance of Magento\Catalog\Model\Product\Interceptor given – seeni Nov 22 '18 at 9:14
  • @seeni : share your export button code... – Ashish Raj Nov 22 '18 at 11:44
  • <exportButton name="export_button"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="selectProvider" xsi:type="string">product_listing.product_listing.product_columns.ids</item> </item> </argument> </exportButton> – seeni Nov 22 '18 at 12:43
  • try once with <exportButton name="export_button" /> – Ashish Raj Nov 23 '18 at 5:22

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.