0

I have ui_component which was using custom data provider. My problem is the Export functionality <exportButton name="export_button"/> is not working. It throws error: Call to a member function setCurrentPage() on null

enter image description here

enter image description here

Do you have any idea on how to fix this without creating new data provider?

1 Answer 1

0

Figured out the problem.

"Using the wrong Dataprovider type."

Basically there are two kinds, you can refer below link:

Magento 2 Data Providers

Please check the Listing.xml file and compare it from below Example :

<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">zipcode_listing.zipcode_listing_data_source</item>
        <item name="deps" xsi:type="string">zipcode_listing.zipcode_listing_data_source</item>
    </item>
    <item name="spinner" xsi:type="string">zipcode_columns</item>
    <item name="buttons" xsi:type="array">
        <item name="add" xsi:type="array">
            <item name="name" xsi:type="string">add</item>
            <item name="label" xsi:type="string" translate="true">Add New Zipcode</item>
            <item name="class" xsi:type="string">primary</item>
            <item name="url" xsi:type="string">*/*/new</item>
        </item>
    </item>
</argument>
<dataSource name="zipcode_listing_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
        <argument name="name" xsi:type="string">zipcode_listing_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">zipcode_id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="update_url" xsi:type="url" path="mui/index/render"/>
                <item name="storageConfig" xsi:type="array">
                    <item name="indexField" xsi:type="string">zipcode_id</item>
                </item>
            </item>
        </argument>
    </argument>
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
        </item>
    </argument>
</dataSource>
<container name="listing_top">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="template" xsi:type="string">ui/grid/toolbar</item>
        </item>
    </argument>
    <bookmark name="bookmarks"/>
    <component name="columns_controls">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="columnsData" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns</item>
                </item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
                <item name="displayArea" xsi:type="string">dataGridActions</item>
            </item>
        </argument>
    </component>
    <exportButton name="export_button">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="selectProvider" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns.ids</item>
            </item>
        </argument>
    </exportButton>
    <filterSearch name="fulltext">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing_data_source</item>
                <item name="chipsProvider" xsi:type="string">zipcode_listing.zipcode_listing.listing_top.listing_filters_chips</item>
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current.search</item>
                </item>
            </item>
        </argument>
    </filterSearch>
    <filters name="listing_filters">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="columnsProvider" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns</item>
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current.filters</item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.listing_top.listing_filters</item>
                    <item name="imports" xsi:type="array">
                        <item name="visible" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns.${ $.index }:visible</item>
                    </item>
                </item>
            </item>
        </argument>
    </filters>
    <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="confirm" xsi:type="array">
                        <item name="title" xsi:type="string" translate="true">Delete items</item>
                        <item name="message" xsi:type="string" translate="true">Delete selected items?</item>
                    </item>
                    <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="checkdelivery/zipcode/massDelete"/>
                </item>
            </argument>
        </action>
        <action name="status">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">status</item>
                    <item name="label" xsi:type="string" translate="true">Change status</item>
                </item>
            </argument>
            <argument name="actions" xsi:type="array">
                <item name="0" xsi:type="array">
                    <item name="type" xsi:type="string">enable</item>
                    <item name="label" xsi:type="string" translate="true">Enable</item>
                    <item name="url" xsi:type="url" path="checkdelivery/zipcode/massStatus">
                        <param name="status">1</param>
                    </item>
                </item>
                <item name="1" xsi:type="array">
                    <item name="type" xsi:type="string">disable</item>
                    <item name="label" xsi:type="string" translate="true">Disable</item>
                    <item name="url" xsi:type="url" path="checkdelivery/zipcode/massStatus">
                        <param name="status">2</param>
                    </item>
                </item>
            </argument>
        </action>
    </massaction>
    <paging name="listing_paging">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current.paging</item>
                </item>
                <item name="selectProvider" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns.ids</item>
            </item>
        </argument>
    </paging>
</container>
<columns  name="zipcode_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">zipcode_listing.zipcode_listing.listing_top.bookmarks</item>
                <item name="namespace" xsi:type="string">current</item>
            </item>
            <item name="childDefaults" xsi:type="array">
                <item name="fieldAction" xsi:type="array">
                    <item name="provider" xsi:type="string">zipcode_listing.zipcode_listing.zipcode_columns_editor</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">zipcode_listing.zipcode_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">zipcode_id</item>
                <item name="sortOrder" xsi:type="number">0</item>
            </item>
        </argument>
    </selectionsColumn>
    <column name="zipcode_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">textRange</item>
                <item name="sorting" xsi:type="string">asc</item>
                <!--<item name="add_field" xsi:type="boolean">true</item>-->
                <item name="label" xsi:type="string" translate="true">ID</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
    </column>
    <column name="zipcode">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <!--<item name="add_field" xsi:type="boolean">true</item>-->
                <item name="label" xsi:type="string" translate="true">Zipcode</item>
                <item name="sortOrder" xsi:type="number">20</item>
            </item>
        </argument>
    </column>

    <column name="city">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <!--<item name="add_field" xsi:type="boolean">true</item>-->
                <item name="label" xsi:type="string" translate="true">City</item>
                <item name="sortOrder" xsi:type="number">30</item>
            </item>
        </argument>
    </column>
</columns>

DataProvider : No need to create external Dataprovider, you can use the core UI Component DataProvider

i.e Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider as mentioned in zipcode_listing.

The last thing you need is to set register zipcode_listing_data_source in di.xml where you configure collection for your grid.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

   <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="zipcode_listing_data_source" xsi:type="string">RB\CheckDelivery\Model\ResourceModel\Zipcode\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

   <type name="RB\CheckDelivery\Model\ResourceModel\Zipcode\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">rb_zipcodes</argument>
            <argument name="resourceModel" xsi:type="string">RB\CheckDelivery\Model\ResourceModel\Zipcode</argument>
        </arguments>
    </type>  </config>

RB\CheckDelivery\Model\ResourceModel\Zipcode\Grid\Collection :

<?php

namespace RB\CheckDelivery\Model\ResourceModel\Zipcode\Grid;

use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Psr\Log\LoggerInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;

class Collection extends SearchResult {


    public function __construct(
        EntityFactoryInterface $entityFactory, 
        LoggerInterface $logger, 
        FetchStrategyInterface $fetchStrategy, 
        ManagerInterface $eventManager, 
        $mainTable, 
        $resourceModel
    ) {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
    }

}

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.