I have created a custom module, that allows commenting, well now I have created admin grid and there is a little problem. Hope you can help! My custom module's table:

comment_id | product_id | created_at | email | name | comment | status_id

And my adming grid:

date | product_name (which displays product_id for now) | name | comment | status
  1. So my first question is, how can I join product collection to my custom table, so I could be able to display product name in the product name column?

  2. And my second question is, I have table status_id in database table and values are 1 and 0, how can I display these ID'š in admin grid as "approved" and "not approved"?

I created my admin grid using UI component.

EDIT: OK now I'm trying to do it like this. Collection class:


namespace Magebit\ProductComments\Model\ResourceModel\Comments;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection
     * Define model & resource model
    protected function _construct()

    protected function initSelect()
            ['catalog_product_entity_varchar' => $this->getTable('catalog_product_entity_varchar')],
            'main_table.product_id = catalog_product_entity_varchar.entity_id',
            ['product_name' => 'value']

        return $this;

And then in ui component listing.xml:

<column name="product_name">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="editor" xsi:type="array">
                <item name="editorType" xsi:type="string">text</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
            <item name="label" xsi:type="string" translate="true">Product Name</item>

But it's not working, is there something else I should do?

1 Answer 1


For case 1, you can use the following code.

$collection = $this->_productCollectionFactory->create(); // get product collection
$joinType = "left"; // join type
$where = ""; // put condition
$fields = "*"; // fields
    ['custom' => 'custom_table'],
    'custom.product_id = e.entity_id',
  • Ok, but where I should add this code? In collection class? Jan 16, 2018 at 10:57
  • Where you want to show the products ? Jan 16, 2018 at 11:01
  • As is said, I have my custom module's admin grid, which now displays product id, I want it to show that product name! prnt.sc/i158sk Jan 16, 2018 at 11:07
  • You have to in _prepareCollection method in grid block file of you custom module. Jan 16, 2018 at 12:32
  • But I used UI components creating admin grid, so I dont have grid block file. Jan 16, 2018 at 12:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.