Magento – how to create grid using ui component with multi table(JOIN) in magento2

gridjsonmagento2uicomponent

I have created a grid with UI component with one table now I want to join another table so how can I create??

i try but not working
in
Vendorname\Modulename\Model\ResourceModel\Quote\collection.php

protected function _initSelect()
    {
        parent::_initSelect();

        $this->getSelect()->joinLeft(
                ['secondTable' => $this->getTable('quote_customer')],
                'main_table.mcs_quote_id = secondTable.quote_request_id',
                array('*')
            );
    }

enter image description here
Thanks in advance.

Best Answer

You can display values from join two tables by using below model resource collection class function

Add below function to your model resource collection function

protected function _initSelect()
    {
        parent::_initSelect();

        $this->getSelect()->joinLeft(
                ['secondTable' => $this->getTable('tablename')],
                'main_table.columnname = secondTable.columnname',
                ['columnname1','columnname2','columnname3']
            );
    }

You can get more information from here magento2: admin grid showing joined table

Related Topic