Magento 1.9 – How to Remove Columns from Admin Grid Export

csvexportmagento-1.9order-grid

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);
    }

Best Answer

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.

Related Topic