I followed this tutorial to create a custom module: http://inchoo.net/magento/how-to-create-a-custom-grid-from-scratch/

Now I want to add the ability to check mark specific rows and export just those to CSV. What is the best approach?

Here is what I have in the Grid.php:

 protected function _prepareMassaction() {

    $this->getMassactionBlock()->setFormFieldName('picklist_order_grid');  //html name of checkbox
    $this->getMassactionBlock()->addItem('export', array(
        'label'=> __('Export Selected'),
        'url'  => $this->getUrl('*/*/exportSelectedPicklistCsv'),   //an action defined in the controller
        'selected' => 'selected',
        'confirm' => __('Are you sure?')

return $this;


Which calls this function in the controller:

public function exportSelectedPicklistCsvAction()
    $fileName = 'picklist.csv';
    $grid = $this->getLayout()->createBlock('kevando_picklist/adminhtml_sales_order_grid');
    $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());

This exportSelectedPicklistCsvAction() function works fine when I have export all the visible items, but not the ones which are check marked.

Any type of help or other SO links are appreciated.



Take a look at app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php

 * Cancel selected orders
public function massCancelAction()
    $orderIds = $this->getRequest()->getPost('order_ids', array());
    $countCancelOrder = 0;
    $countNonCancelOrder = 0;
    foreach ($orderIds as $orderId) {

$orderIds = $this->getRequest()->getPost('order_ids', array()); contain all the checkbox ids you selected. So you need to use the ids as a filter in 'kevando_picklist/adminhtml_sales_order_grid'

  • Thanks, this is a great start. What is the best way to filter the collection in the grid? I can't think of a way to do it that doesn't effect the grid every other time it gets prepared. – kevando Oct 29 '14 at 14:07
  • What i would recommend is to accept this question, then post a new question "how to filter by id" and add exportSelectedPicklistCsvAction() and your grid code – Renon Stewart Oct 29 '14 at 14:37
  • ;P And add a link to the new question ..... – snh_nl Jan 6 '17 at 7:29

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.