- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2021
06:11 AM
09-13-2021
06:11 AM
How to add image column in the configurations field Magento 2
In this function
protected function _prepareToRender() { $this->addColumn( 'attribute', [ 'label' => __('Select Attribute'), 'renderer' => $this->getAttributeRenderer(), ] ); $this->addColumn( 'test_thumbnail', array( 'header' => __('Image'), 'index' => 'test_thumbnail', 'renderer' => 'xxxxxxx\xxxxxxxxx\Block\Adminhtml\Product\Attribute\Edit\Tab\Renderer\Image', ) ); $this->addColumn('test_content',['label' => __('Test Content')]); $this->addColumn('position', ['label' => __('Position')]); $this->_addAfter = false; $this->_addButtonLabel = __('Add'); }
Please help.
Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2021
03:44 AM
09-14-2021
03:44 AM
Re: How to add image column in the configurations field Magento 2
Please use the below code
$this->addColumn( 'image', [ 'header' => __('Image'), 'index' => 'image', 'type' => 'image', 'frame_callback' => array($this, 'callback_image'), ] );
Return image frame from callback function
public function callback_image($value) { if (empty($value)){ return ''; } $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $mediaUrl = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); $width = 150; return "<img src='" . $mediaUrl . $value . "' width='" . $width . "'/>"; }
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.
200+ Magento 2 Extensions for Enhanced Shopping Experience.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2021
07:02 AM
09-14-2021
07:02 AM
Re: How to add image column in the configurations field Magento 2
Hi @Sanjay Jethva
I have tried your same code
$this->addColumn( 'question_thumbnail', [ 'header' => __('Image'), 'index' => 'question_thumbnail', 'type' => 'image', 'frame_callback' => array($this, 'callback_image'), ] );
I am getting "question_thumbnail is not defined" in console and still iam getting the text field in grid edit page instead of image type.
https://ibb.co/yQXHwjJ
I need to add image column here after the select attribute column.
On click Add dynamic rows will add. In that each row will select an attribute(color, size etc.,) and need to browse and upload an image for each selected attribute.