2

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?

9

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) {.

  • This works cool, but is there anyother way, by which I could skip adding columns, I mean like adding the column names to collection or so, because I have four more columns to be added and may be more in future. – Shathish Sep 14 '13 at 7:20
  • maybe you can override the export methods in your grid. tage a look at getCsvFile, getCsv, getXml, getExcelFile, getExcel in Mage_Adminhtml_Block_Widget_Grid and see what you can change – Marius Sep 14 '13 at 7:36
  • sure, i'll try and will post, if i am successful. Thanks! – Shathish Sep 14 '13 at 10:21
  • @Marius : Actually 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, could you pls help me. – user51361 Apr 27 '17 at 7:33

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.