0

Fyi, I did read from another similar post where I came to a good solution (Setting is system true will prevent it from getting exported).

However, my problem is I would like to have two type of csv export where the first type will export all columns. The second type will only export certain column. I cant set is_system true as this will hide the columns from both types of export function. Is there any way to set condition in the controller where it can set is_system true to the grid or any alternative way?

Beforehand, let me thank you in advance.

   public function example()
    {
        $fileName   = 'example.csv';
        $content    = $this->getLayout()->createBlock('example/example_grid')
            ->getCsv();

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

//Grid

$this->addColumn('detail', array(
    'header'    => Mage::helper('example')->__('Detail'),
    'align'     => 'left',
    'renderer'  => 'example/example'
));
0

I would suggest to create a new grid file with wanted columns only and then call the grid from controller.

Like this:

In your main Grid.php

protected function _prepareColumns()
{

    .......................
    ...............
    other stuff
    .................

    $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
    $this->addExportType('*/*/exportCsvWithoutSomeColumn', Mage::helper('sales')->__('CSV Without some column'));

    return parent::_prepareColumns();
}

In your controller:

/**
 * Export order grid to CSV format
 */
public function exportCsvAction()
{
    $fileName   = 'your_file_name.csv';
    $grid       = $this->getLayout()->createBlock('module/path_to_grid');
    //$grid       = $this->getLayout()->createBlock('adminhtml/sales_order_grid');
    $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
}


/**
 * Export order grid to CSV format
 */
public function exportCsvWithoutSomeColumnAction()
{
    $fileName   = 'your_file_name_without_column.csv';
    $grid       = $this->getLayout()->createBlock('module/path_to_gridwithoutsomecolumn');
    $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
}

Now, create another grid, copy _prepareCollection() function from your main grid and paste in here

<?php
//new grid extends your original gri
class NameSpace_ModuleName_Block_Adminhtml_Path_To_Gridwithoutsomecolumn extends Mage_Adminhtml_Block_Widget_Grid
{
     public function __construct()
    {
        parent::__construct();
        $this->setId('your_grid');
        $this->setDefaultSort('your_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }

    protected function _prepareCollection()
    {
      //only allowed column
    }
}

Now, remove unwanted column and then save.

This should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.