Magento 2 add column to sales returns grid
Question
How to add column to sales returns grid,
returns grid using _prepareColumns
to add columns to grid \Magento\Rma\Block\Adminhtml\Rma\Grid
No correct solution
OTHER TIPS
Try with below way!
Extend Magento RMA block file to your custom module.
app/code/Namespace/Modulename/Block/Adminhtml/Rma
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
namespace Namespace\Modulename\Block\Adminhtml\Rma;
/**
* RMA Grid
*/
class Grid extends \Magento\Rma\Block\Adminhtml\Rma\Grid
{
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Rma\Model\ResourceModel\Rma\Grid\CollectionFactory $collectionFactory
* @param \Magento\Rma\Model\RmaFactory $rmaFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Rma\Model\ResourceModel\Rma\Grid\CollectionFactory $collectionFactory,
\Magento\Rma\Model\RmaFactory $rmaFactory,
array $data = array())
{
parent::__construct(
$context,
$backendHelper,
$collectionFactory,
$rmaFactory,
$data);
}
/**
* Prepare related item collection
*
* @return \Magento\Rma\Block\Adminhtml\Rma\Grid
*/
protected function _prepareCollection()
{
$this->_beforePrepareCollection();
return parent::_prepareCollection();
}
/**
* Configuring and setting collection
*
* @return $this
*/
protected function _beforePrepareCollection()
{
if (!$this->getCollection()) {
/** @var $collection \Magento\Rma\Model\ResourceModel\Rma\Grid\Collection */
$collection = $this->_collectionFactory->create();
$this->setCollection($collection);
}
return $this;
}
/**
* Prepare grid columns
*
* @return \Magento\Rma\Block\Adminhtml\Rma\Grid
*/
protected function _prepareColumns()
{
parent::_prepareColumns();
$this->addColumn(
'custom_column',
[
'header' => __('Custom Column'),
'index' => 'custom_column',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]
);
return $this;
}
/**
* Prepare massaction
*
* @return $this
*/
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('entity_ids');
$this->getMassactionBlock()->addItem(
'status',
[
'label' => __('Close'),
'url' => $this->getUrl($this->_getControllerUrl('close')),
'confirm' => __(
'You have chosen to change status(es) of the selected RMA requests to Close.'
. ' Are you sure you want to continue?'
)
]
);
return $this;
}
/**
* Get Url to action
*
* @param string $action action Url part
* @return string
*/
protected function _getControllerUrl($action = '')
{
return '*/*/' . $action;
}
/**
* Retrieve row url
*
* @param \Magento\Framework\DataObject $row
* @return string
*/
public function getRowUrl($row)
{
return $this->getUrl($this->_getControllerUrl('edit'), ['id' => $row->getId()]);
}
}
It will be showing like below.
I hope it helps!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange