2

I have 2 grid that i want to use in my custom module, the first grid have actions column that have link to access the second grid, the problem is i want to load data in second grid (listingproduct) based on the first grid primary id which will be send via url like this:

                    'lazada' => [
                        'href' => $this->urlBuilder->getUrl(
                            'test_lazada/listingproduct/index',
                            [
                                'listing_id' => $item['listing_id']
                            ]
                        ),
                        'label' => __('List')
                    ]

it will generated lnk like this:

localhost/admin/lime_lazada/listingproduct/index/listing_id/<listing_id>/key/<form_key>

the listing_id is the primary key i'm gonna use to filter the second grid datasource, here's how i define the datasource for my first grid and second grid in di.xml:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- first grid  -->
    <virtualType name="Lime\Lazada\Model\ResourceModel\Listing\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">lime_listing</argument>
            <argument name="resourceModel" xsi:type="string">Lime\Lazada\Model\ResourceModel\Listing\Collection</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="lime_listing_grid_data_source" xsi:type="string">Lime\Lazada\Model\ResourceModel\Listing\Grid\Collection</item>
                <item name="lime_listingproduct_grid_data_source" xsi:type="string">Lime\Lazada\Model\ResourceModel\Listingproduct\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <!-- second grid  -->
    <virtualType name="Lime\Lazada\Model\ResourceModel\Listingproduct\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">lime_listingproduct</argument>
            <argument name="resourceModel" xsi:type="string">Lime\Lazada\Model\ResourceModel\Listingproduct\Collection</argument>
        </arguments>
    </virtualType>
</config>

here's my Adminhtml/Listingproduct/Index.php:

namespace Lime\Lazada\Controller\Adminhtml\Listingproduct;

class Index extends \Magento\Backend\App\Action
{

    protected $resultPageFactory;

    /**
     * Constructor
     *
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * Index action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
            $resultPage->getConfig()->getTitle()->prepend(__("listingproduct"));
            return $resultPage;
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.