- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016
06:28 AM
05-31-2016
06:28 AM
custom grid
How show image in custom grid on magento 2 ?
I use renderer, but it does not work.
$this->addColumn(
'image',
[
'header' => __('Image'),
'index' => 'image',
'renderer' => "MyVendor\Gallery\Block\Adminhtml\Gallery\Grid\Renderer\Image",
'filter' => false
]);
Help please !!
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016
08:59 AM
05-31-2016
08:59 AM
Re: custom grid
Hi @Saitama1488
Can you update your question with code in the Image block code?
---
Problem Solved Click Accept as Solution!:Magento Community India Forum
Problem Solved Click Accept as Solution!:Magento Community India Forum
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016
07:16 AM
06-03-2016
07:16 AM
Re: custom grid
Hello Saitama,
Check out the following code :
$this->addColumn( 'image', [ 'header' => __('Image'), 'index' => 'image', 'renderer' => "MyVendor\Gallery\Block\Adminhtml\Gallery\Grid\Renderer\Image", 'filter' => false ]);
Then I created a renderer block as below:
namespace YourVendor\YourModule\Block\Adminhtml\Gallery\Grid\Renderer; use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer; use Magento\Framework\Object; use Magento\Store\Model\StoreManagerInterface; class Image 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(Object $row) { $mediaDirectory = $this->_storeManager->getStore()->getBaseUrl( \Magento\Framework\UrlInterface::URL_TYPE_MEDIA ); $imageUrl = $mediaDirectory.'/inquiry/images'.$this->_getValue($row); return '<img src="'.$imageUrl.'" width="50"/>'; } }
Try once and reply if still have any issue. Hope this also work for you.