Question

I have a custom admin grid, which shows the feedback given by customers during checkout. I have 19 fields in the custom_table including entity_id, created_at and updated_at.

This is my form view: enter image description here

This is my grid view: enter image description here

everything works fine. Now when I export the grid as csv/ xml/ excel, it would only export the fields in the grid, but I want all the data in my database-table to be exported. How can I do that? Also If i apply filter in that grid, only those rows should be exported.

note: customer name and email_id are displayed by joining the sales/order table

This is my _prepareCollection() function in Grid.php

protected function _prepareCollection(){
    $collection = Mage::getModel('feedbacktest/feedback')->getCollection();
    // join the order table to display in the grid.
    $collection->join('sales/order', 'increment_id=order_id', array('orderId'=>'entity_id', 'custName'=>'concat(customer_firstname," ",customer_lastname)', 'custEmail'=>'customer_email'), null,'left');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Collection gives me all the data (as I require), but exported data contains only the data in the grid.

Can someone help me on this?

Was it helpful?

Solution

You can add in your grid columns that are visible only on export.
In the _prepareColumns() method add this:

if ($this->_isExport) { 
    $this->addColumn('col_id', array(
        'header' => Mage::helper('helper_alias')->__('Header'),
        'index'  => 'col_id',
    ));
}

Just like any other column, just wrapped in if ($this->_isExport) {.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top