0

I am joining 3 tables with my custom table and data are showing in the admin grid is perfect but in the pagination, first, new clicks are working eg: when we on 1st page pagination next link working and go to 2nd page. then click on the prev pagination button the same listing data are shown. Here is my code

 <?xml version="1.0" ?>
<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">vendor_reports_order_listing.vendor_reports_order_listing_data_source</item>
        </item>
    </argument>
    <settings>
        <spinner>vendor_reports_order_columns</spinner>
        <deps>
            <dep>vendor_reports_order_listing.vendor_reports_order_listing_data_source</dep>
        </deps>
    </settings>
    <dataSource component="Magento_Ui/js/grid/provider" name="vendor_reports_order_listing_data_source">
        <settings>
            <updateUrl path="vendor_reports/orders/render"/>
        </settings>
        <dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="vendor_reports_order_listing_data_source">
            <settings>
                <requestFieldName>item_id</requestFieldName>
                <primaryFieldName>main_table.item_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <listingToolbar name="listing_top">
        <settings>
            <sticky>true</sticky>
        </settings>
        <columnsControls name="columns_controls"/>
        <filters name="listing_filters"/>
        <paging name="listing_paging"/>
    </listingToolbar>
    <listingToolbar name="listing_top">
        <settings>
            <sticky>true</sticky>
        </settings>
        <columnsControls name="columns_controls"/>
        <exportButton name="export_button"/>
        <filterSearch name="fulltext"/>
        <filters name="listing_filters">
            <filterSelect name="store_id" provider="${ $.parentName }">
                <settings>
                    <options class="Magento\Store\Ui\Component\Listing\Column\Store\Options"/>
                    <caption translate="true">All Store Views</caption>
                    <label translate="true">Purchase Point</label>
                    <dataScope>store_id</dataScope>
                    <imports>
                        <link name="visible">ns = ${ $.ns }, componentType = column, index = ${ $.index }:visible</link>
                    </imports>
                </settings>
            </filterSelect>
        </filters>
    </listingToolbar>
    <columns name="vendor_reports_order_columns">
        <selectionsColumn name="ids">
            <settings>
                <indexField>item_id</indexField>
            </settings>
        </selectionsColumn>
        <column name="thumbnail" class="vendor\Reports\Ui\Component\Listing\Column\Thumbnail">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
                    <!-- <item name="add_field" xsi:type="boolean">true</item> -->
                    <item name="sortable" xsi:type="boolean">false</item>
                    <item name="altField" xsi:type="string">name</item>
                    <item name="has_preview" xsi:type="string">1</item>
                    <item name="label" xsi:type="string" translate="true">Image</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                </item>
            </argument>
        </column>
        <column name="increment_id">
            <settings>
                <filter>text</filter>
                <label translate="true">ID</label>
            </settings>
        </column>
        <column name="sku">
            <settings>
                <filter>text</filter>
                <label translate="true">Sku</label>
            </settings>
        </column>
        <column name="name">
            <settings>
                <filter>text</filter>
                <label translate="true">Product Name</label>
            </settings>
        </column>
        <column name="brand_new_value">
            <settings>
                <filter>text</filter>
                <label translate="true">Brand New Value</label>
            </settings>
        </column>
        <column name="brand_size">
            <settings>
                <filter>text</filter>
                <label translate="true">Brand Size</label>
            </settings>
        </column>
        <column name="color_value">
            <settings>
                <filter>text</filter>
                <label translate="true">Color Value</label>
            </settings>
        </column>
        <column name="price">
            <settings>
                <filter>text</filter>
                <label translate="true">Price</label>
            </settings>
        </column>
        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <label translate="true">Purchase Date</label>
                <sorting>desc</sorting>
            </settings>
        </column>
    </columns>
</listing>

Here is my collection class

class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
{
    /**
     * @var string
     */
    protected $_idFieldName = 'item_id';

    /**
     * Event prefix
     *
     * @var string
     */
    protected $_eventPrefix = 'sales_order_item_collection';

    /**
     * Event object
     *
     * @var string
     */
    protected $_eventObject = 'order_item_collection';

    /**
     * Order field for setOrderFilter
     *
     * @var string
     */
    protected $_orderField = 'order_id';

    /**
     * Model initialization
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(\Magento\Sales\Model\Order\Item::class, \Magento\Sales\Model\ResourceModel\Order\Item::class);
    }

    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger,
        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        $mainTable = 'sales_order_item',
        $resourceModel = null,
        $identifierName = null,
        $connectionName = null
    ) {
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $mainTable,
            $resourceModel,
            $identifierName,
            $connectionName
        );
    }

    protected function _initSelect()
    {
        parent::_initSelect();
//        $this->addFilterToMap('created_at', 'main_table.created_at');
//        $this->addFilterToMap('sku', 'main_table.sku');
//        $this->addFilterToMap('entity_id', 'main_table.item_id');
        $salesOrder = $this->getTable('sales_order');
        $category = $this->getTable('catalog_category_product');
        $categoryFlat1 = $this->getTable('catalog_category_flat_store_1');
        $productFlat1 = $this->getTable('catalog_product_flat_1');
        $this->getSelect()->joinInner(
            ['so' => $salesOrder],
            'so.entity_id = main_table.order_id',
            ['increment_id','status']
        )->joinInner(
            ['ccp' => $category],
            'ccp.product_id = main_table.product_id',
            []
        )->joinLeft(
            ['cp' => $categoryFlat1],
            'cp.entity_id = ccp.category_id',
            ['name']
        )->joinLeft(
            ['pf' => $productFlat1],
            'pf.entity_id = main_table.product_id',
            ['brand_new_value','brand_size','color_value','price','thumbnail']
        )->group('main_table.item_id');
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.