Magento 2: how can I remove columns in exported csv from order grid?How can I export fields which are not being displayed in admin grid?Export CSV file from order gridDataflow Profiles - Not amending customers - creating new oneCSV “Pick slip” from Sales Order GridIssue in Exporting CSV file from a custom moduleAdmin Grid - Remove columns from exportCan't find Magento attributes for Custom Export moduleCreate order progamatically with all parameter in magento 2?Magento 2 : Currency Symbol missing when exporting Saler Order GridHow to Spilt Address in Customer grid CSV Export
How can I prevent interns from being expendable?
The deliberate use of misleading terminology
Adding strings in lists together
Is floating in space similar to falling under gravity?
My player wants to cast multiple charges of magic missile from a wand
Possible nonclassical ion from a bicyclic system
find the Integer value after a string from a file
Differences between “pas vrai ?”, “c’est ça ?”, “hein ?”, and “n’est-ce pas ?”
Get LaTeX form from step by step solution
When a current flow in an inductor is interrupted, what limits the voltage rise?
Intuition behind eigenvalues of an adjacency matrix
Points within polygons in different projections
How was Apollo supposed to rendezvous in the case of a lunar abort?
What does "tea juice" mean in this context?
Is there an evolutionary advantage to having two heads?
In what episode of TOS did a character on the bridge make a comment about raising the number 1 to some power?
Fastest way to perform complex search on pandas dataframe
Modern approach to radio buttons
Expenditure in Poland - Forex doesn't have Zloty
count number of files in directory with a certain name
Can't connect to Internet in bash using Mac OS
Are there regional foods in Westeros?
Infinitely many hats
What caused the tendency for conservatives to not support climate change regulations?
Magento 2: how can I remove columns in exported csv from order grid?
How can I export fields which are not being displayed in admin grid?Export CSV file from order gridDataflow Profiles - Not amending customers - creating new oneCSV “Pick slip” from Sales Order GridIssue in Exporting CSV file from a custom moduleAdmin Grid - Remove columns from exportCan't find Magento attributes for Custom Export moduleCreate order progamatically with all parameter in magento 2?Magento 2 : Currency Symbol missing when exporting Saler Order GridHow to Spilt Address in Customer grid CSV Export
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want remove columns while exporting order grid data in magento 2. I google it but didn't find solution. Like I want to remove these fields from exported csv.
- Payment Method
- Total Refunded
- Customer Group
- Grand Total (Base)
- Purchase Point

magento-2.1 csv export order-grid
add a comment |
I want remove columns while exporting order grid data in magento 2. I google it but didn't find solution. Like I want to remove these fields from exported csv.
- Payment Method
- Total Refunded
- Customer Group
- Grand Total (Base)
- Purchase Point

magento-2.1 csv export order-grid
add a comment |
I want remove columns while exporting order grid data in magento 2. I google it but didn't find solution. Like I want to remove these fields from exported csv.
- Payment Method
- Total Refunded
- Customer Group
- Grand Total (Base)
- Purchase Point

magento-2.1 csv export order-grid
I want remove columns while exporting order grid data in magento 2. I google it but didn't find solution. Like I want to remove these fields from exported csv.
- Payment Method
- Total Refunded
- Customer Group
- Grand Total (Base)
- Purchase Point

magento-2.1 csv export order-grid
magento-2.1 csv export order-grid
asked Mar 28 '17 at 16:59
AbhishekAbhishek
450824
450824
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Try following way:
Create Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<exportButton name="export_button" class="VendorModuleComponentExportButton" />
</listingToolbar>
</listing>
And Create Vendor/Module/Component/ExportButton.php
namespace VendorModuleComponent;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkUrlInterface;
class ExportButton extends MagentoUiComponentAbstractComponent
/**
* Component name
*/
const NAME = 'exportButton';
/**
* @var MagentoFrameworkUrlInterface
*/
protected $urlBuilder;
/**
* @param ContextInterface $context
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
parent::__construct($context, $components, $data);
$this->urlBuilder = $urlBuilder;
/**
* Get component name
*
* @return string
*/
public function getComponentName()
return static::NAME;
/**
* @return void
*/
public function prepare()
$config = $this->getData('config');
if (isset($config['options']))
$config['options'] = [];
$this->setData('config', $config);
parent::prepare();
Clear cache.
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
add a comment |
Right now it is not possible to change columns for export. See: https://github.com/magento/magento2/issues/3079
add a comment |
Extend MagentoUiModelExportConvertToCsv file in to your custom module to extend model file create di.xml
and in your extended file add below conditions to remove unwanted columns and column value in order export CSV Format.
if($component->getName()=='sales_order_grid')
$fieldsVal = $this->metadataProvider->getFields($component);
$removeFieldsArr = array('column names which you want to remove goes here ..');
foreach($fieldsVal as $key=>$val)
if(in_array($val,$removeFieldsArr))
unset($fieldsVal[$key]);
$fields = array_values($fieldsVal);
else
$fields = $this->metadataProvider->getFields($component);
add a comment |
Let me do that for you with step by step.
First Step: Register your export button in your: view/adminhtml/ui_component/[grid-view-id].xml
<exportButton name="export_button" class="NamespaceAdvancedReportComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/export</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">my_advancedreport/export/gridToCsv</item>
</item>
</item>
</item>
</argument>
</exportButton>
Of course, you need a controller to do this thing:
namespace NamespaceAdvancedReportControllerAdminhtmlExport;
class GridToCsv extends MagentoUiControllerAdminhtmlExportGridToCsv
const ADMIN_RESOURCE = 'My_AdvancedReport::advanced_invoice_report';
Second Step: Modify your controller class to use custom Export Model. /code/Namespace/AdvancedReport/etc/di.xml (scope global or Adminhtml)
<type name="NamespaceAdvancedReportModelExportConvertToCsv">
<arguments>
<argument name="metadataProvider" xsi:type="object">NamespaceAdvancedReportModelExportMetadataProvider</argument>
</arguments>
</type>
<type name="NamespaceAdvancedReportControllerAdminhtmlExportGridToCsv">
<arguments>
<argument name="converter" xsi:type="object">NamespaceAdvancedReportModelExportConvertToCsv</argument>
</arguments>
</type>
Custom data provider to get what are selected columns user have selected on Admin.
app/code/Namespace/AdvancedReport/Model/Export/MetadataProvider.php
about the idea I have used MagentoUiModelBookmarkManagement. to get stored grid for Admin User while User Edit selected or sort-ordered columns of the Report Grid.
namespace NamespaceAdvancedReportModelExport;
use MagentoFrameworkViewElementUiComponentInterface;
use MagentoUiComponentMassActionFilter;
use MagentoFrameworkLocaleResolverInterface;
use MagentoFrameworkStdlibDateTimeTimezoneInterface;
class MetadataProvider extends MagentoUiModelExportMetadataProvider
/**
* @var MagentoUiModelBookmarkManagement
*/
protected $_bookmarkManagement;
/**
* MetadataProvider constructor.
* @param Filter $filter
* @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver
* @param string $dateFormat
* @param MagentoUiModelBookmarkManagement $bookmarkManagement
* @param array $data
*/
public function __construct(
Filter $filter,
TimezoneInterface $localeDate,
ResolverInterface $localeResolver,
MagentoUiModelBookmarkManagement $bookmarkManagement,
$dateFormat = 'M j, Y H:i:s A',
array $data = [])
parent::__construct($filter, $localeDate, $localeResolver, $dateFormat, $data);
$this->_bookmarkManagement = $bookmarkManagement;
protected function getActiveColumns($component)
$bookmark = $this->_bookmarkManagement->getByIdentifierNamespace('current', $component->getName());
$config = $bookmark->getConfig();
$columns = $config['current']['columns'];
$_activeColumns = [];
foreach ($columns as $column => $config)
if(true === $config['visible'] && $column != 'ids')
$_activeColumns[] = $column;
return $_activeColumns;
/**
* @param UiComponentInterface $component
* @return UiComponentInterface[]
* @throws Exception
*/
protected function getColumns(UiComponentInterface $component)
if (!isset($this->columns[$component->getName()]))
$activeColumns = $this->getActiveColumns($component);
$columns = $this->getColumnsComponent($component);
foreach ($columns->getChildComponents() as $column)
if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions')
if(in_array($column->getName(), $activeColumns))
$this->columns[$component->getName()][$column->getName()] = $column;
return $this->columns[$component->getName()];
Done.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f166610%2fmagento-2-how-can-i-remove-columns-in-exported-csv-from-order-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try following way:
Create Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<exportButton name="export_button" class="VendorModuleComponentExportButton" />
</listingToolbar>
</listing>
And Create Vendor/Module/Component/ExportButton.php
namespace VendorModuleComponent;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkUrlInterface;
class ExportButton extends MagentoUiComponentAbstractComponent
/**
* Component name
*/
const NAME = 'exportButton';
/**
* @var MagentoFrameworkUrlInterface
*/
protected $urlBuilder;
/**
* @param ContextInterface $context
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
parent::__construct($context, $components, $data);
$this->urlBuilder = $urlBuilder;
/**
* Get component name
*
* @return string
*/
public function getComponentName()
return static::NAME;
/**
* @return void
*/
public function prepare()
$config = $this->getData('config');
if (isset($config['options']))
$config['options'] = [];
$this->setData('config', $config);
parent::prepare();
Clear cache.
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
add a comment |
Try following way:
Create Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<exportButton name="export_button" class="VendorModuleComponentExportButton" />
</listingToolbar>
</listing>
And Create Vendor/Module/Component/ExportButton.php
namespace VendorModuleComponent;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkUrlInterface;
class ExportButton extends MagentoUiComponentAbstractComponent
/**
* Component name
*/
const NAME = 'exportButton';
/**
* @var MagentoFrameworkUrlInterface
*/
protected $urlBuilder;
/**
* @param ContextInterface $context
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
parent::__construct($context, $components, $data);
$this->urlBuilder = $urlBuilder;
/**
* Get component name
*
* @return string
*/
public function getComponentName()
return static::NAME;
/**
* @return void
*/
public function prepare()
$config = $this->getData('config');
if (isset($config['options']))
$config['options'] = [];
$this->setData('config', $config);
parent::prepare();
Clear cache.
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
add a comment |
Try following way:
Create Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<exportButton name="export_button" class="VendorModuleComponentExportButton" />
</listingToolbar>
</listing>
And Create Vendor/Module/Component/ExportButton.php
namespace VendorModuleComponent;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkUrlInterface;
class ExportButton extends MagentoUiComponentAbstractComponent
/**
* Component name
*/
const NAME = 'exportButton';
/**
* @var MagentoFrameworkUrlInterface
*/
protected $urlBuilder;
/**
* @param ContextInterface $context
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
parent::__construct($context, $components, $data);
$this->urlBuilder = $urlBuilder;
/**
* Get component name
*
* @return string
*/
public function getComponentName()
return static::NAME;
/**
* @return void
*/
public function prepare()
$config = $this->getData('config');
if (isset($config['options']))
$config['options'] = [];
$this->setData('config', $config);
parent::prepare();
Clear cache.
Try following way:
Create Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<exportButton name="export_button" class="VendorModuleComponentExportButton" />
</listingToolbar>
</listing>
And Create Vendor/Module/Component/ExportButton.php
namespace VendorModuleComponent;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkUrlInterface;
class ExportButton extends MagentoUiComponentAbstractComponent
/**
* Component name
*/
const NAME = 'exportButton';
/**
* @var MagentoFrameworkUrlInterface
*/
protected $urlBuilder;
/**
* @param ContextInterface $context
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
parent::__construct($context, $components, $data);
$this->urlBuilder = $urlBuilder;
/**
* Get component name
*
* @return string
*/
public function getComponentName()
return static::NAME;
/**
* @return void
*/
public function prepare()
$config = $this->getData('config');
if (isset($config['options']))
$config['options'] = [];
$this->setData('config', $config);
parent::prepare();
Clear cache.
answered Mar 29 '17 at 4:36
Sohel RanaSohel Rana
25k34663
25k34663
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
add a comment |
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
You can access exprt buttons options then, but in these options you cannot influence what columns will be exported.
– skymeissner
Sep 22 '17 at 8:27
add a comment |
Right now it is not possible to change columns for export. See: https://github.com/magento/magento2/issues/3079
add a comment |
Right now it is not possible to change columns for export. See: https://github.com/magento/magento2/issues/3079
add a comment |
Right now it is not possible to change columns for export. See: https://github.com/magento/magento2/issues/3079
Right now it is not possible to change columns for export. See: https://github.com/magento/magento2/issues/3079
answered Dec 7 '17 at 22:06
MehdiMehdi
609721
609721
add a comment |
add a comment |
Extend MagentoUiModelExportConvertToCsv file in to your custom module to extend model file create di.xml
and in your extended file add below conditions to remove unwanted columns and column value in order export CSV Format.
if($component->getName()=='sales_order_grid')
$fieldsVal = $this->metadataProvider->getFields($component);
$removeFieldsArr = array('column names which you want to remove goes here ..');
foreach($fieldsVal as $key=>$val)
if(in_array($val,$removeFieldsArr))
unset($fieldsVal[$key]);
$fields = array_values($fieldsVal);
else
$fields = $this->metadataProvider->getFields($component);
add a comment |
Extend MagentoUiModelExportConvertToCsv file in to your custom module to extend model file create di.xml
and in your extended file add below conditions to remove unwanted columns and column value in order export CSV Format.
if($component->getName()=='sales_order_grid')
$fieldsVal = $this->metadataProvider->getFields($component);
$removeFieldsArr = array('column names which you want to remove goes here ..');
foreach($fieldsVal as $key=>$val)
if(in_array($val,$removeFieldsArr))
unset($fieldsVal[$key]);
$fields = array_values($fieldsVal);
else
$fields = $this->metadataProvider->getFields($component);
add a comment |
Extend MagentoUiModelExportConvertToCsv file in to your custom module to extend model file create di.xml
and in your extended file add below conditions to remove unwanted columns and column value in order export CSV Format.
if($component->getName()=='sales_order_grid')
$fieldsVal = $this->metadataProvider->getFields($component);
$removeFieldsArr = array('column names which you want to remove goes here ..');
foreach($fieldsVal as $key=>$val)
if(in_array($val,$removeFieldsArr))
unset($fieldsVal[$key]);
$fields = array_values($fieldsVal);
else
$fields = $this->metadataProvider->getFields($component);
Extend MagentoUiModelExportConvertToCsv file in to your custom module to extend model file create di.xml
and in your extended file add below conditions to remove unwanted columns and column value in order export CSV Format.
if($component->getName()=='sales_order_grid')
$fieldsVal = $this->metadataProvider->getFields($component);
$removeFieldsArr = array('column names which you want to remove goes here ..');
foreach($fieldsVal as $key=>$val)
if(in_array($val,$removeFieldsArr))
unset($fieldsVal[$key]);
$fields = array_values($fieldsVal);
else
$fields = $this->metadataProvider->getFields($component);
answered Apr 2 at 11:57
NilimaNilima
1
1
add a comment |
add a comment |
Let me do that for you with step by step.
First Step: Register your export button in your: view/adminhtml/ui_component/[grid-view-id].xml
<exportButton name="export_button" class="NamespaceAdvancedReportComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/export</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">my_advancedreport/export/gridToCsv</item>
</item>
</item>
</item>
</argument>
</exportButton>
Of course, you need a controller to do this thing:
namespace NamespaceAdvancedReportControllerAdminhtmlExport;
class GridToCsv extends MagentoUiControllerAdminhtmlExportGridToCsv
const ADMIN_RESOURCE = 'My_AdvancedReport::advanced_invoice_report';
Second Step: Modify your controller class to use custom Export Model. /code/Namespace/AdvancedReport/etc/di.xml (scope global or Adminhtml)
<type name="NamespaceAdvancedReportModelExportConvertToCsv">
<arguments>
<argument name="metadataProvider" xsi:type="object">NamespaceAdvancedReportModelExportMetadataProvider</argument>
</arguments>
</type>
<type name="NamespaceAdvancedReportControllerAdminhtmlExportGridToCsv">
<arguments>
<argument name="converter" xsi:type="object">NamespaceAdvancedReportModelExportConvertToCsv</argument>
</arguments>
</type>
Custom data provider to get what are selected columns user have selected on Admin.
app/code/Namespace/AdvancedReport/Model/Export/MetadataProvider.php
about the idea I have used MagentoUiModelBookmarkManagement. to get stored grid for Admin User while User Edit selected or sort-ordered columns of the Report Grid.
namespace NamespaceAdvancedReportModelExport;
use MagentoFrameworkViewElementUiComponentInterface;
use MagentoUiComponentMassActionFilter;
use MagentoFrameworkLocaleResolverInterface;
use MagentoFrameworkStdlibDateTimeTimezoneInterface;
class MetadataProvider extends MagentoUiModelExportMetadataProvider
/**
* @var MagentoUiModelBookmarkManagement
*/
protected $_bookmarkManagement;
/**
* MetadataProvider constructor.
* @param Filter $filter
* @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver
* @param string $dateFormat
* @param MagentoUiModelBookmarkManagement $bookmarkManagement
* @param array $data
*/
public function __construct(
Filter $filter,
TimezoneInterface $localeDate,
ResolverInterface $localeResolver,
MagentoUiModelBookmarkManagement $bookmarkManagement,
$dateFormat = 'M j, Y H:i:s A',
array $data = [])
parent::__construct($filter, $localeDate, $localeResolver, $dateFormat, $data);
$this->_bookmarkManagement = $bookmarkManagement;
protected function getActiveColumns($component)
$bookmark = $this->_bookmarkManagement->getByIdentifierNamespace('current', $component->getName());
$config = $bookmark->getConfig();
$columns = $config['current']['columns'];
$_activeColumns = [];
foreach ($columns as $column => $config)
if(true === $config['visible'] && $column != 'ids')
$_activeColumns[] = $column;
return $_activeColumns;
/**
* @param UiComponentInterface $component
* @return UiComponentInterface[]
* @throws Exception
*/
protected function getColumns(UiComponentInterface $component)
if (!isset($this->columns[$component->getName()]))
$activeColumns = $this->getActiveColumns($component);
$columns = $this->getColumnsComponent($component);
foreach ($columns->getChildComponents() as $column)
if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions')
if(in_array($column->getName(), $activeColumns))
$this->columns[$component->getName()][$column->getName()] = $column;
return $this->columns[$component->getName()];
Done.
add a comment |
Let me do that for you with step by step.
First Step: Register your export button in your: view/adminhtml/ui_component/[grid-view-id].xml
<exportButton name="export_button" class="NamespaceAdvancedReportComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/export</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">my_advancedreport/export/gridToCsv</item>
</item>
</item>
</item>
</argument>
</exportButton>
Of course, you need a controller to do this thing:
namespace NamespaceAdvancedReportControllerAdminhtmlExport;
class GridToCsv extends MagentoUiControllerAdminhtmlExportGridToCsv
const ADMIN_RESOURCE = 'My_AdvancedReport::advanced_invoice_report';
Second Step: Modify your controller class to use custom Export Model. /code/Namespace/AdvancedReport/etc/di.xml (scope global or Adminhtml)
<type name="NamespaceAdvancedReportModelExportConvertToCsv">
<arguments>
<argument name="metadataProvider" xsi:type="object">NamespaceAdvancedReportModelExportMetadataProvider</argument>
</arguments>
</type>
<type name="NamespaceAdvancedReportControllerAdminhtmlExportGridToCsv">
<arguments>
<argument name="converter" xsi:type="object">NamespaceAdvancedReportModelExportConvertToCsv</argument>
</arguments>
</type>
Custom data provider to get what are selected columns user have selected on Admin.
app/code/Namespace/AdvancedReport/Model/Export/MetadataProvider.php
about the idea I have used MagentoUiModelBookmarkManagement. to get stored grid for Admin User while User Edit selected or sort-ordered columns of the Report Grid.
namespace NamespaceAdvancedReportModelExport;
use MagentoFrameworkViewElementUiComponentInterface;
use MagentoUiComponentMassActionFilter;
use MagentoFrameworkLocaleResolverInterface;
use MagentoFrameworkStdlibDateTimeTimezoneInterface;
class MetadataProvider extends MagentoUiModelExportMetadataProvider
/**
* @var MagentoUiModelBookmarkManagement
*/
protected $_bookmarkManagement;
/**
* MetadataProvider constructor.
* @param Filter $filter
* @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver
* @param string $dateFormat
* @param MagentoUiModelBookmarkManagement $bookmarkManagement
* @param array $data
*/
public function __construct(
Filter $filter,
TimezoneInterface $localeDate,
ResolverInterface $localeResolver,
MagentoUiModelBookmarkManagement $bookmarkManagement,
$dateFormat = 'M j, Y H:i:s A',
array $data = [])
parent::__construct($filter, $localeDate, $localeResolver, $dateFormat, $data);
$this->_bookmarkManagement = $bookmarkManagement;
protected function getActiveColumns($component)
$bookmark = $this->_bookmarkManagement->getByIdentifierNamespace('current', $component->getName());
$config = $bookmark->getConfig();
$columns = $config['current']['columns'];
$_activeColumns = [];
foreach ($columns as $column => $config)
if(true === $config['visible'] && $column != 'ids')
$_activeColumns[] = $column;
return $_activeColumns;
/**
* @param UiComponentInterface $component
* @return UiComponentInterface[]
* @throws Exception
*/
protected function getColumns(UiComponentInterface $component)
if (!isset($this->columns[$component->getName()]))
$activeColumns = $this->getActiveColumns($component);
$columns = $this->getColumnsComponent($component);
foreach ($columns->getChildComponents() as $column)
if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions')
if(in_array($column->getName(), $activeColumns))
$this->columns[$component->getName()][$column->getName()] = $column;
return $this->columns[$component->getName()];
Done.
add a comment |
Let me do that for you with step by step.
First Step: Register your export button in your: view/adminhtml/ui_component/[grid-view-id].xml
<exportButton name="export_button" class="NamespaceAdvancedReportComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/export</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">my_advancedreport/export/gridToCsv</item>
</item>
</item>
</item>
</argument>
</exportButton>
Of course, you need a controller to do this thing:
namespace NamespaceAdvancedReportControllerAdminhtmlExport;
class GridToCsv extends MagentoUiControllerAdminhtmlExportGridToCsv
const ADMIN_RESOURCE = 'My_AdvancedReport::advanced_invoice_report';
Second Step: Modify your controller class to use custom Export Model. /code/Namespace/AdvancedReport/etc/di.xml (scope global or Adminhtml)
<type name="NamespaceAdvancedReportModelExportConvertToCsv">
<arguments>
<argument name="metadataProvider" xsi:type="object">NamespaceAdvancedReportModelExportMetadataProvider</argument>
</arguments>
</type>
<type name="NamespaceAdvancedReportControllerAdminhtmlExportGridToCsv">
<arguments>
<argument name="converter" xsi:type="object">NamespaceAdvancedReportModelExportConvertToCsv</argument>
</arguments>
</type>
Custom data provider to get what are selected columns user have selected on Admin.
app/code/Namespace/AdvancedReport/Model/Export/MetadataProvider.php
about the idea I have used MagentoUiModelBookmarkManagement. to get stored grid for Admin User while User Edit selected or sort-ordered columns of the Report Grid.
namespace NamespaceAdvancedReportModelExport;
use MagentoFrameworkViewElementUiComponentInterface;
use MagentoUiComponentMassActionFilter;
use MagentoFrameworkLocaleResolverInterface;
use MagentoFrameworkStdlibDateTimeTimezoneInterface;
class MetadataProvider extends MagentoUiModelExportMetadataProvider
/**
* @var MagentoUiModelBookmarkManagement
*/
protected $_bookmarkManagement;
/**
* MetadataProvider constructor.
* @param Filter $filter
* @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver
* @param string $dateFormat
* @param MagentoUiModelBookmarkManagement $bookmarkManagement
* @param array $data
*/
public function __construct(
Filter $filter,
TimezoneInterface $localeDate,
ResolverInterface $localeResolver,
MagentoUiModelBookmarkManagement $bookmarkManagement,
$dateFormat = 'M j, Y H:i:s A',
array $data = [])
parent::__construct($filter, $localeDate, $localeResolver, $dateFormat, $data);
$this->_bookmarkManagement = $bookmarkManagement;
protected function getActiveColumns($component)
$bookmark = $this->_bookmarkManagement->getByIdentifierNamespace('current', $component->getName());
$config = $bookmark->getConfig();
$columns = $config['current']['columns'];
$_activeColumns = [];
foreach ($columns as $column => $config)
if(true === $config['visible'] && $column != 'ids')
$_activeColumns[] = $column;
return $_activeColumns;
/**
* @param UiComponentInterface $component
* @return UiComponentInterface[]
* @throws Exception
*/
protected function getColumns(UiComponentInterface $component)
if (!isset($this->columns[$component->getName()]))
$activeColumns = $this->getActiveColumns($component);
$columns = $this->getColumnsComponent($component);
foreach ($columns->getChildComponents() as $column)
if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions')
if(in_array($column->getName(), $activeColumns))
$this->columns[$component->getName()][$column->getName()] = $column;
return $this->columns[$component->getName()];
Done.
Let me do that for you with step by step.
First Step: Register your export button in your: view/adminhtml/ui_component/[grid-view-id].xml
<exportButton name="export_button" class="NamespaceAdvancedReportComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/export</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">my_advancedreport/export/gridToCsv</item>
</item>
</item>
</item>
</argument>
</exportButton>
Of course, you need a controller to do this thing:
namespace NamespaceAdvancedReportControllerAdminhtmlExport;
class GridToCsv extends MagentoUiControllerAdminhtmlExportGridToCsv
const ADMIN_RESOURCE = 'My_AdvancedReport::advanced_invoice_report';
Second Step: Modify your controller class to use custom Export Model. /code/Namespace/AdvancedReport/etc/di.xml (scope global or Adminhtml)
<type name="NamespaceAdvancedReportModelExportConvertToCsv">
<arguments>
<argument name="metadataProvider" xsi:type="object">NamespaceAdvancedReportModelExportMetadataProvider</argument>
</arguments>
</type>
<type name="NamespaceAdvancedReportControllerAdminhtmlExportGridToCsv">
<arguments>
<argument name="converter" xsi:type="object">NamespaceAdvancedReportModelExportConvertToCsv</argument>
</arguments>
</type>
Custom data provider to get what are selected columns user have selected on Admin.
app/code/Namespace/AdvancedReport/Model/Export/MetadataProvider.php
about the idea I have used MagentoUiModelBookmarkManagement. to get stored grid for Admin User while User Edit selected or sort-ordered columns of the Report Grid.
namespace NamespaceAdvancedReportModelExport;
use MagentoFrameworkViewElementUiComponentInterface;
use MagentoUiComponentMassActionFilter;
use MagentoFrameworkLocaleResolverInterface;
use MagentoFrameworkStdlibDateTimeTimezoneInterface;
class MetadataProvider extends MagentoUiModelExportMetadataProvider
/**
* @var MagentoUiModelBookmarkManagement
*/
protected $_bookmarkManagement;
/**
* MetadataProvider constructor.
* @param Filter $filter
* @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver
* @param string $dateFormat
* @param MagentoUiModelBookmarkManagement $bookmarkManagement
* @param array $data
*/
public function __construct(
Filter $filter,
TimezoneInterface $localeDate,
ResolverInterface $localeResolver,
MagentoUiModelBookmarkManagement $bookmarkManagement,
$dateFormat = 'M j, Y H:i:s A',
array $data = [])
parent::__construct($filter, $localeDate, $localeResolver, $dateFormat, $data);
$this->_bookmarkManagement = $bookmarkManagement;
protected function getActiveColumns($component)
$bookmark = $this->_bookmarkManagement->getByIdentifierNamespace('current', $component->getName());
$config = $bookmark->getConfig();
$columns = $config['current']['columns'];
$_activeColumns = [];
foreach ($columns as $column => $config)
if(true === $config['visible'] && $column != 'ids')
$_activeColumns[] = $column;
return $_activeColumns;
/**
* @param UiComponentInterface $component
* @return UiComponentInterface[]
* @throws Exception
*/
protected function getColumns(UiComponentInterface $component)
if (!isset($this->columns[$component->getName()]))
$activeColumns = $this->getActiveColumns($component);
$columns = $this->getColumnsComponent($component);
foreach ($columns->getChildComponents() as $column)
if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions')
if(in_array($column->getName(), $activeColumns))
$this->columns[$component->getName()][$column->getName()] = $column;
return $this->columns[$component->getName()];
Done.
answered May 23 at 8:58
HoangHieuHoangHieu
754514
754514
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f166610%2fmagento-2-how-can-i-remove-columns-in-exported-csv-from-order-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown