1

I have a custom grid using ui component method in back-end to show data from a custom table with columns as follows:

id 
product_id 
user_id 
store_ids 
status 
adminassign 
created 
modified 
position

Here the product_id, user_id, status denotes default Product ID, Customer ID and Product Status respectively. Now I have displayed these values in the custom grid.
How can I join the default catalog_product and customer tables to show more fields like Product Name, Product Image, Product Status and Customer Name in to the grid.

Please help me out. Thank you in advance.

asked Nov 25, 2019 at 11:33

1 Answer 1

2

You can add _initSelect() method in your Collection.php file in your custom module

protected function _initSelect()
{
 parent::_initSelect();
 $this->getSelect()->joinLeft(
 ['cp' => $this->getTable('catalog_product')],
 'main_table.product_id = cp.entity_id',
 ['*']
 );
 return $this;
}

You can check this module as a reference link.

Hope this will help you!

answered Nov 25, 2019 at 12:15
11
  • Let me know if it helps. Thanks. Commented Nov 26, 2019 at 7:46
  • Do you mean the Collection class Myvendor\Mymodule\Model\ResourceModel\Pendingproducts\Collection mentioned in di.xml? (like the one in the code below:) <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"> <arguments> <argument name="collections" xsi:type="array"> <item name="entity_listing_data_source1" xsi:type="string">Myvendor\Mymodule\Model\ResourceModel\Pendingproducts\Collection</item> </argument> </arguments> </type> Commented Nov 27, 2019 at 10:27
  • Yes, Exactly you need to add this in your app\code\Myvendor\Mymodule\Model\ResourceModel\Pendingproducts\Collection.php file Commented Nov 27, 2019 at 10:29
  • I added the _initSelect() method to Collection.php, but it seems like the code is not being run. Because it is not showing anything when I tried to echo the collection query or even added exit() afterwards. Any idea why? Commented Dec 4, 2019 at 5:45
  • Please check your di.xml file if you've created VirtualType there for collection then we need to add this initselect using dataprovider file. Commented Dec 4, 2019 at 5:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.