I have a custom module in admin panel,when I click at "Export" button following function is called. CSV is being exported and downloaded correctly, in CSV one column is having id's instead of value of field.So I just want to changes to the value for that column, But I can't find where data is being dumped into csv file.

class Abc_AddressManager_Adminhtml_StoresController extends
Mage_Adminhtml_Controller_Action {
 public function exportCsvAction() {
    $fileName = 'stores.csv';
    $content = $this->getLayout()->createBlock('abc_addressmanager/adminhtml_stores_csv')

    $this->_prepareDownloadResponse($fileName, $content);


class Abc_AddressManager_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Widget_Grid

protected function _prepareCollection() {
    $customer_id = $this->getRequest()->getParam('id');

    $collection = Mage::getResourceModel('customer/address_collection');
    $select = $collection->getSelect();

            array('customer' => $collection->getTable('customer/entity')), 'customer.entity_id=e.parent_id', array('email' => 'email')

    $d = $collection->getSelect()->__toString();

    return parent::_prepareCollection();
protected function _prepareColumns() {

    $addressModel = Mage::getModel('customer/address');
    $addressForm = Mage::getModel('customer/form');
    $attributes = $addressForm->getAttributes();

    $this->addColumn('email', array(
        'header' => 'email',
        'type' => 'text',
        'index' => 'email',
        'filter' => false,
        'sortable' => false,
$this->addColumn('entity_id', array(
            'header' => 'address_id',
            'type' => 'text',
            'index' => 'entity_id',
            'filter' => false,
            'sortable' => false,
    foreach ($attributes as $attribute) {

        $code = $attribute->getData('attribute_code');

        $this->addColumn($code, array(
            'header' => $code,
            'type' => 'text',
            'index' => $code,
            'filter' => false,
            'sortable' => false,
    } // end 

    return $this;

My field Column is "Ownership", that is a customer attribute, type drop down,its attribute_id =554 in eav_attribute table, and option id's are =438 to 443 in eav_attribute_option, and values for option is stored in eav_attribute_option_value,in csv file, column name is Ownership, but its has option id's(438 to 443) in it, instead of their value. My grid look like this.As you can see, Ownership has value(CO), in csv it here I am getting '439' option_id for "CO" Admin grip

2 Answers 2


You should override _prepareColumns function inside your custom block

Class abc_Addressmanager_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Report_Grid_Abstract {

     protected function _prepareCollection()
          //please make sure to set collection here and having all columns you want to load in the query

     protected function _prepareColumns()
        //for debuging
        $collection = $this->getCollection();
        //printing the query using this command (if $collection object is set)
        echo   $collection->getSelect();
        //making sure the fields you want to show up is in the query output
        //you can add or remove columns here

  • Can see my update Feb 15, 2016 at 7:42
  • I am doing as you said Feb 15, 2016 at 7:42
  • could you show up adminhtml grid?
    – phanvugiap
    Feb 15, 2016 at 7:47
  • you can see it, I can't show full grid, it is too large Feb 15, 2016 at 8:01
  • I added some tips for you above. Hope it helps
    – phanvugiap
    Feb 15, 2016 at 8:08

The block is extending Mage_Adminhtml_Block_Widget_Grid which has this function getCsvFile Now following the calls from there:

  • getCsvFile is calling _exportCsvItem
  • _exportCsvItem calls Mage_Adminhtml_Block_Widget_Grid_Column::getRowFieldExport
  • Now getRowFieldExport calls $this->getRenderer()->renderExport($row);
  • Wich is found in the abstract renderer Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract and calls $this->render($row);

Now in your case it should be the "Select" Renderer which is Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Select you can find the render function there, or it might be another Render, you can insert log code and test which one is it.

  • I have debugged my project, it always calls to render() from 'Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Longtext', not from 'Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Select' as you said. Feb 16, 2016 at 4:48

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.