Magento – Joining two collection / tables

collection;databasejoin-tablemagento-1.9

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.

Best Answer

$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();



    }
}
Related Topic