1

I have situation I want to join two tables having some data related to orders.One table contain order id as increment_id and other table contain order id as order_id.I am joining the tables through customer_id.Now the thing is when we display the column in backend grid we define some column name to it.But now I have two columns containing different names.Then how I can use data of both the column together and can give name to grid column. Till now my join code is

$collection = Mage::getModel('creditlog/creditlog')->getCollection();
        $collection->addFieldToFilter('main_table.customer_id', $this->getRequest()->getParam('id'));

        $logTable = Mage::getSingleton('core/resource')->getTableName('creditlog/logdata');

        $collection->getSelect()->join(array('a'=> $logTable),
       'main_table.customer_id = a.customer_id', array('order_id','credit_amount','date','status'));

And my grid column is

$this->addColumn('increment_id', array(
            'header' => Mage::helper('creditlog')->__('Your orders'),
            'index' => 'increment_id',
            'type' => 'text',
                )
        );

Please help.

8
  • your can use 'renderer' => 'Spacename_Modulename_Block_Adminhtml_Action', to show that data if it is about displaying data in one column. ` Feb 4, 2016 at 5:09
  • can you guide me using union instead of join? Feb 4, 2016 at 5:40
  • sorry i don't get get it is about not join working? or about showing the result in grid? Feb 4, 2016 at 5:43
  • Join is working fine but the result not of use.As it will result in two column with different name so how will show them in grid.? Feb 4, 2016 at 6:09
  • you want to show column value in same column or two different column? Feb 4, 2016 at 6:12

1 Answer 1

2
$this->addColumn('increment_id', array(
            'header' => Mage::helper('creditlog')->__('Your orders'),
            'index' => 'increment_id',
            'renderer' => 'Spacename_Modulename_Block_Adminhtml_Action',
                )
        );

and your renderer block

 class Spacename_Moduelename_Block_Adminhtml_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{

    public function render(Varien_Object $row)
    {


    return $row->getIncrementId().''. $row->getOrderId();



    }
}

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.