/**
  * Iterate collection and call callback method per item
  * For callback method first argument always is item object
  *
  * @param string $callback
  * @param array $args additional arguments for callback method
  * @return Mage_Adminhtml_Block_Widget_Grid
  */
 public function _exportIterateCollection($callback, array $args)
 {
     if (!is_array($this->_blcg_exportInfos)) {
         return parent::_exportIterateCollection($callback, $args);
     } else {
         // Custom export
         if (!is_null($this->_blcg_exportedCollection)) {
             $originalCollection = $this->_blcg_exportedCollection;
         } else {
             $originalCollection = $this->getCollection();
         }
         if ($originalCollection->isLoaded()) {
             // Should do the trick in all exceptions (if not loaded page size can be changed)
             Mage::throwException(Mage::helper('customgrid')->__('This grid does not seem to be compatible with the custom export. If you wish to report this problem, please indicate this class name : "%s"', get_class($this)));
         }
         // 1000 up to 1.4, class var from 1.5
         $exportPageSize = isset($this->_exportPageSize) ? $this->_exportPageSize : 1000;
         $infos = $this->_blcg_exportInfos;
         $total = isset($infos['custom_size']) ? intval($infos['custom_size']) : (isset($infos['size']) ? intval($infos['size']) : $exportPageSize);
         if ($total <= 0) {
             return;
         }
         $fromResult = isset($infos['from_result']) ? intval($infos['from_result']) : 1;
         $pageSize = min($total, $exportPageSize);
         $page = ceil($fromResult / $pageSize);
         $pitchSize = $fromResult > 1 ? $fromResult - 1 - ($page - 1) * $pageSize : 0;
         $break = false;
         $count = null;
         while ($break !== true) {
             $collection = clone $originalCollection;
             $collection->setPageSize($pageSize);
             $collection->setCurPage($page);
             if (!is_null($this->_blcg_typeModel)) {
                 $this->_blcg_typeModel->beforeGridExportLoadCollection($this, $collection);
             }
             $collection->load();
             if (!is_null($this->_blcg_typeModel)) {
                 $this->_blcg_typeModel->afterGridExportLoadCollection($this, $collection);
             }
             if (is_null($count)) {
                 $count = $collection->getSize();
                 $total = min(max(0, $count - $fromResult + 1), $total);
                 if ($total == 0) {
                     $break = true;
                     continue;
                 }
                 $first = true;
                 $exported = 0;
             }
             $page++;
             $i = 0;
             foreach ($collection as $item) {
                 if ($first) {
                     if ($i++ < $pitchSize) {
                         continue;
                     } else {
                         $first = false;
                     }
                 }
                 if (++$exported > $total) {
                     $break = true;
                     break;
                 }
                 call_user_func_array(array($this, $callback), array_merge(array($item), $args));
             }
         }
     }
 }