I added csv export in admin grid and want to have export functionality whether admin user have filtered results or not. now I'm filtering data by daterange. some dates are working properly and gives me csv file like this enter image description here and some dates not giving me a csv file and all I'm getting is a blank page.

all data export not working at all. this is my code to create a csv file:

            $component = $this->filter->getComponent();
            $dataProvider = $component->getContext()->getDataProvider();
            $dataProvider->setLimit(0, false);
            $searchResult = $component->getContext()->getDataProvider()->getSearchResult();
            $name = md5(microtime());
            $file = 'export/' . $component->getName() . $name . '.csv';
            $stream = $this->directory->openFile($file, 'w+');
            $header = [
                'Customer ID',
                'Customer Name',
                'Customer Mobile',
                'Comment To Customer',
                'Comment To Admin',
                'Balance Change',
                'Transaction Date',
                'Customer Notified',
                'Created By',
//            var_dump(count($searchResult->getItems()));
            foreach ($searchResult->getItems() as $document) {

                $content = [
                    $document->getCommentToAdmin() ?? '',
                    (new TransactionType)->getBalanceUpdateLabel($document->getType()),
                    (new NotifiedStatus)->getStatusValue($document->getBalanceUpdateNotified()),
                    $document->getCreatedBy() ? $document->getCreatedBy() : '',
//                echo "<pre>";
//                var_dump($content);
//                echo "</pre>";
            $date = $shamsi->toJalaliTime((new \DateTime())->format('Y-m-d H:i:s'));
            return $this->fileFactory->create("TransactionReport_$date.csv", [
                'type' => 'filename',
                'value' => $file,
                'rm' => true  // can delete file after use
            ], 'var');

before foreach i wrote count($searchResult->getItems()) result is correct, but after foreach i don't have any data! this is my var_dump() data after getting a blank page : enter image description here

as you can see array (size=353) 353 records!

1 Answer 1


Found the solution!


Magento couldn't find customer with email address because user doesn't exists in Db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.