Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5488

How to apply join in collection in UIComponent Grid in magento 2

$
0
0

Magneto-Code-Snippet

To create a grid using UI-component in magento 2, please refer following link:

http://webkul.com/blog/how-to-create-a-grid-using-ui-component/

To apply join in grid collection you need to add following code in your grid collection file, which is defined in :Webkul\Hello\etc\di.xml

Add Your code in file:

Webkul\Hello\Model\ResourceModel\Employee\Grid\Collection

    protected function _renderFiltersBefore() {
       	$joinTable = $this->getTable('customer_grid_flat');
        $this->getSelect()->join($joinTable.' as customer','main_table.entity_id = customer.entity_id', array('*'));
        parent::_renderFiltersBefore();
    }

Here, $JoinTable: is table with which you want to apply join.
main_table:  is your grid collection table.
array(‘*’):  use for accessing all the fields of the table.

If you want to select specific columns then add those column names in place of ‘*’ under array().

like: array(‘firstname’=>’firstname’)


Viewing all articles
Browse latest Browse all 5488

Trending Articles