首頁>Magento>source

从管理網格匯出(CSV)資料時,如果我選擇單个條目,即使它正在匯出整个工作表.我無法匯出單个條目。使用下面的代碼.請提出建議。

<?php
/**
 *
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Sm\Sample\Controller\Adminhtml\Sample;
use Magento\Backend\Block\Widget\Grid\ExportInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
class ExportCsv extends \Magento\Backend\App\Action
{
/**
     * @var \Magento\Framework\App\Response\Http\FileFactory
     */
    protected $_fileFactory;
    /**
     * @var \Magento\Framework\View\Result\LayoutFactory
     */
    protected $resultLayoutFactory;
    /**
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
     * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
        \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
    ) {
        $this->_fileFactory = $fileFactory;
        $this->resultLayoutFactory = $resultLayoutFactory;
        parent::__construct($context);
    }
    /**
     * Export subscribers grid to CSV format
     *
     * @return ResponseInterface
     */
    public function execute()
    {
       $fileName = 'exportCsv.csv';
        $content = $this->_view->getLayout()->createBlock(
            'Sm\Sample\Block\Adminhtml\Sample\Grid'
        )->setSaveParametersInSession(
            true
        )->getCsv();
        return $this->_fileFactory->create($fileName, $content);
    }
    /**
     * {@inheritdoc}
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Sm_Sample::sample');
    }
}
最新回復
  • 2019-8-17
    1 #

    通過選中massaction複選框,您無法匯出單个記錄。 您需要使用 Filter fields来縮短列表   並單击 Export   按钮。

  • pagespeed:Magento 1936-效能突然下降
  • magento2:將getSingleton(&ndquo; core / resource”) - > getConnection($ type)从Magento 1轉換為Magento 2