0

Trying to export the full grid data of a custom module. The function itself works but there's a limit of 20 (well a limit of how many rows are visible on the page). I need to export the full data from the button. I tried adding: $grid->setDefaultLimit(4000) but I realised that 4000 isn't always going to be correct. So I need something to say do all data. Here's my current function:

<?php
    class Namespae_Module_Adminhtml_GridController extends Mage_Adminhtml_Controller_Action {
        protected function _createSerializerBlock($inputName, Mage_Adminhtml_Block_Widget_Grid $gridBlock, $productsArray) {
            return $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_ajax_serializer')
                ->setGridBlock($gridBlock)
                ->setProducts($productsArray)
                ->setInputElementName($inputName);
        }

        public function indexAction() {
            $this->loadLayout();
            $this->_setActiveMenu('adminhtml/grid/index');
            $this->_addContent($this->getLayout()->createBlock('namespace_module/adminhtml_grid'));
            $this->renderLayout();
        }

        public function exportCsvAction() {
            $filename = 'inventory_report-' . date('d-m-Y') . '_' . date('H:i:s') . '.csv';
            $grid     = $this->getLayout()->createBlock('namespace_module/adminhtml_grid');
            //$grid->setDefaultLimit(4000);

            $this->_prepareDownloadResponse($filename, $grid->getCsvFile());
        }
    }

As I said, it all works but I need it for all data, not just what's visible on the screen.

How can I go about doing this??

0

Have you tried to extend getCsvFile() method?

Something like that should take of limiting and paging from your collection:

// ...

$this->getCollection()->getSelect()->limit();
$this->getCollection()->setPageSize(0);
$this->getCollection()->load();
foreach ($this->getCollection() as $item) {
  $io->streamWriteCsv(array( // ...
  • I have not yet, will give it a go :) – 123TFO Aug 25 '16 at 9:04

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.