How to Manage Grid UI Component in Magento 2?

Learn how to manage grid UI component using Dataprovider in Magento with a few steps.

In Magento 2, the UI component is used to build a grid on admin 1 and instead of block and template in Magento 1.

But when using it with a custom dataprovider in Magento 2, you may have a problem like this:

Launch Your Multi-Vendor Marketplace Business Model With Magento Solution!!!

The reason for the Magento 2 cores’ export control is that they use the setCurPage () function instead of the setCurPage () function.

So you should add this function to your collection file. The example below illustrates this issue more clearly.

Classify Dataprovider UI component file In Magento

Manage Grid UI Component in Magento 2

File directory: app/code/Webnexs/OrderSuccess/view/ui_component/os_needverify_listing.xml

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

        ...

    </argument>

    <dataSource name="os_needverify_listing_data_source">

        <argument name="dataProvider" xsi:type="configurableObject">

            <argument name="class" xsi:type="string">Webnexs\OrderSuccess\Ui\DataProvider\NeedVerifyDataProvider</argument>

            ...

        </argument>

    </dataSource>

...

</listing>

Init collection in Dataprovider file

File directory: app/code/Webnexs/OrderSuccess/Ui/DataProvider/NeedVerifyDataprovider.php

namespace Webnexs\OrderSuccess\Ui\DataProvider;

class OrderDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider {

    protected $needVerifyCollectionFatory;

    public function __construct(

        $name,

        $primaryFieldName,

        $requestFieldName,

        \Webnexs\OrderSuccess\Model\ResourceModel\Order\NeedVerify\CollectionFactory $needVerifyCollectionFatory,

        array $meta = [],

        array $data = []

    ) {

        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);

        $this->needVerifyCollectionFatory = $needVerifyCollectionFatory;    

        $this->initCollection();

    }



    public function initCollection()

    {

        $collection = $this->needVerifyCollectionFactory()->create();

        $this->collection = $collection;

    }



    public function getSearchCriteria(){

        return $this->getCollection();

    }



}

UI Form resource collection

File directory:

app/code/Webnexs/OrderSuccess/Model/ResourceModel/NeedVerify/Collection.php

namespace Webnexs\OrderSuccess\Model\ResourceModel\Order;

class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult

{

    public function __construct(

        EntityFactory $entityFactory,

        Logger $logger,

        FetchStrategy $fetchStrategy,

        EventManager $eventManager,

        $mainTable = 'sales_order',

        $resourceModel = '\Webnexs\OrderSuccess\Model\ResourceModel\NeedVerify'

    ) {

        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);

    }


    public function getCurrentPage(){

        return $this->getCurPage();

    }

    

    public function setCurrentPage($currentPage){

        return $this->setCurPage($currentPage);

    }

}

Note: We need to get the GetCurrentPage () and setCurrentPage () functionality to getCurPage () and setCurPage () functionality. The problem will be fixed.

The above-mentioned is the simplest process for you to manage Grid UI Component Using Custom Dataprovider. With this information, you can handle the Grid UI Component Using Custom Dataprovider effortlessly.

Contact us to get your Magento store built in a few days!!!

Dataprovider in Magento


Posted

in

, ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *