Magento – add customer email in sales order grid magento

magento-1.7

how can i add customer email in admin html grid magento. i get customer email in collection but not displayed in column of Customer Email. Please Help me.

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->join('order', 'main_table.entity_id = order.entity_id', 'customer_email');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
protected function _prepareColumns()
{
        $this->addColumn('customer_email', array(
        'header' => $this->helper('sales')->__('Customer Email'),
        'index' => 'customer_email',
    ));
}

Best Answer

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft(
        array('myorder'=>'sales_flat_order'),
        'myorder.entity_id = main_table.entity_id',
        array('myorder.customer_email')
    );
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

You need to add filter_index to code

$this->addColumn('customer_email', array(
    'header' => $this->helper('sales')->__('Customer Email'),
    'index' => 'customer_email',
    'filter_index' => 'myorder.customer_email',
));