Magento 2 – How to Add Where Clause in Grid Collection

collection;gridmagento2

I am working on a module, where I have 2 custom tables. One is of all customer who have added product to First table(one customer can add multiple tables) and that first table is displayed on grid.

On grid action I have a action column which has to show all products added added by a customer.

My frist tables structure( table name->rfq)

frist table

my second tables structure (table name->rfqitem)
second table

this code gives output like below

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

    $this->getSelect()->joinLeft(
        ['secondTable' => $this->getTable('rfq')],
        'main_table.rfq_id = secondTable.customer_id', 
        array('main_table.product_id','main_table.qty')
    );
}    

current output
getting

but i expect result like this
expect
So how can achieve this.

thanks

Best Answer

You need to add where clause in joinLeft() query :

$this->getSelect()->joinLeft(
        ['secondTable' => $this->getTable('rfq')],
        'main_table.rfq_id = secondTable.customer_id', 
        array('main_table.product_id','main_table.qty')
    )->where("main_table.id IS NOT null");