UiComponent export button issue, error: getRowData() must be an instance of Magento\Framework\Api\Search\DocumentInterface (Solved by myself)

magento.stackexchange https://magento.stackexchange.com/questions/197037

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 ...

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
scroll top