0

I have a collection like below.

protected function _initSelect() {
        $this->addFilterToMap('entity_id', 'main_table.entity_id');
        $this->addFilterToMap('increment_id', 'main_table.increment_id');
        $this->addFilterToMap('created_at', 'main_table.created_at');       
        $columns = array(  'total_income_amount' => new \Zend_Db_Expr(
            sprintf('SUM((%s - %s))',
                'main_table.base_subtotal',
                'main_table.base_discount_amount'
            )
        ),
        'total_inc_tax_all' => new \Zend_Db_Expr(
            sprintf('SUM((%s - %s + %s))',
                'main_table.base_subtotal',
                'main_table.base_discount_amount',
                'main_table.tax_invoiced'
            )
        )
        );
        parent::_initSelect();       
        
        $this->getSelect()->columns($columns)
        ->joinLeft(
            ['secondTable' => $this->getTable('sales_order_grid')], //2nd table name by which you want to join mail table
            'main_table.entity_id = secondTable.entity_id', // common column which available in both table 
            '*' // '*' define that you want all column of 2nd table. if you want some particular column then you can define as ['column1','column2']
        )->joinLeft(
            ['thirdtable' => $this->getTable('sales_order_address')], //2nd table name by which you want to join mail table
            'main_table.entity_id = thirdtable.entity_id', // common column which available in both table 
            '*' // '*' define that you want all column of 2nd table. if you want some particular column then you can define as ['column1','column2']
        );    
        //'convert(int, base_subtotal)+convert(int, base_discount_amount) as summed from main_table'        
    }

But I get only one record in the admin grid but it is showing multiple pages.

enter image description here

If I remove columns($columns) it is showing all records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.