I have create custom module and render product grid with custom column "Store Price" and that value is saved in custom table with product id. Now I want to render store price in that coulmn. Note: that custom column is rendered from "render" option with Block path in addcolumns.
Prepare columns:
protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('Product Id'),
'sortable' => true,
'index' => 'entity_id',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product Name'),
'index' => 'name'
]
);
$this->addColumn(
'sku',
[
'header' => __('Sku'),
'index' => 'sku'
]
);
$this->addColumn(
'price',
[
'header' => __('Price'),
'index' => 'price'
]
);
$this->addColumn(
'store_price',
[
'header' => __('Store Price'),
'index' => 'entity_id',
'renderer' => '\Vendor\Modulename\Block\Adminhtml\Template\Renderer\StorePrice',
]
);
$this->addColumn(
'product_id',
[
'header' => __('Select Product'),
'sortable' => false,
'type' => 'checkbox',
'field_name' => 'product_id[]',
'index' => 'entity_id',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]
);
return parent::_prepareColumns();
Render File:
namespace Vendor\Modulename\Block\Adminhtml\Template\Renderer;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\DataObject;
use Magento\Store\Model\StoreManagerInterface;
class StorePrice extends AbstractRenderer
{
private $_storeManager;
/**
* @param \Magento\Backend\Block\Context $context
* @param array $data
*/
public function __construct(\Magento\Backend\Block\Context $context, StoreManagerInterface $storemanager, array $data = [])
{
$this->_storeManager = $storemanager;
parent::__construct($context, $data);
$this->_authorization = $context->getAuthorization();
}
/**
* Renders grid column
*
* @param Object $row
* @return string
*/
public function render(DataObject $row)
{
return '<input type="text" maxlength="10" name="product_price[]">';
}
}
Thanks in advanced