Magento – Export a field from custom model grid with a diferent render to Csv

adminhtmlmagento-1.9order-gridrenderersales-order

I created a custom column on sales order grid. It works as well but a used a custom render on a field (like this).

When I export the grid to CSV, the file contains the raw value, but I need apply another render to it for users understand the data.

So how I can do a custom render to column on grid just to export cases?

Best Answer

I got it. There is the renderExport method to do it.

My render file:

class Namespace_MyModule_Block_Adminhtml_Sales_Order_Renderer_Grid_MyModule extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $value =  $row->getData($this->getColumn()->getIndex());

        // CUSTOM PHP CODE FOR MODIFY VALUE HERE

        return $value;
    }

    public function renderExport(Varien_Object $row)
    {
        return $this->render($row); // We can do diferent value for Render Grid and Render Export.
    }
}