4

I am in a situation, where I need to display an email_address1 in grid, and during export have to use other one (email_address2). For this I have added two columns in grid, with email_address1 is visible in grid and with email_address2 will not, as shown

        $this->addColumn('customer_name', array(
            'header' => Mage::helper('sales')->__('Customer'),
            'index' => 'email_address1',
            'width' => '60',
            'type' => 'text',
            'filter_index' => 'email_address1'
        ));

        $this->addColumn('customer_name_ordered', array(
            'header' => Mage::helper('sales')->__('Customer'),
            'index' => 'email_address2',
            'column_css_class'=>'no-display',
            'header_css_class'=>'no-display',
            'width' => '60',
            'type' => 'text',
            'filter_index' => 'email_address2'
        ));

During export (csv or xml), both columns are being exported, how can I stop column with email_address1 from being exported, or please suggest an other solution.

My export action for CSV is like

   public function exportCsvAction() {
        $fileName = 'sales_order_items.csv';
        $content = $this->getLayout()->createBlock('salesorderitemgrid/adminhtml_order_items_grid')->getCsv();

        $this->_sendUploadResponse($fileName, $content);
    }

1 Answer 1

11

Got it, if set is_system true for a column, it will not be exported.So

    $this->addColumn('customer_name', array(
        'header' => Mage::helper('sales')->__('Customer'),
        'index' => 'email_address1',
        'width' => '60',
        'type' => 'text',
        'is_system' => true,
        'filter_index' => 'email_address1'
    ));

    $this->addColumn('customer_name_ordered', array(
        'header' => Mage::helper('sales')->__('Customer'),
        'index' => 'email_address2',
        'column_css_class'=>'no-display',
        'header_css_class'=>'no-display',
        'width' => '60',
        'type' => 'text',
        'filter_index' => 'email_address2'
    ));

Now column with email_address1 will not be exported.

2
  • @ Abdul Ghaffar : I am using this method magento.stackexchange.com/a/171754/51361 for adding custom field on sales order grid. but when i export, the custom added column values not exported, how can i solve this error.
    – user51361
    Commented Apr 27, 2017 at 7:23
  • @Rathinam is your issue resolved? Commented Jun 5, 2017 at 10:52

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.