If you want to set clickable value in the Magento 2 Grid then please follow the below steps. I have made this type of functionality for my custom module.
Step 1: Please add this code to your UI Listing XML. We have added bodyTmpl to make value clickable in the UI column.
1 2 3 4 5 6 7 8 9 10 |
<column name="holiday_id" class="Magemonkeys\Holidaylisting\Ui\Component\Listing\Column\HolidayId"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string" translate="true">ID #</item> <item name="sortOrder" xsi:type="number">10</item> <item name="filter" xsi:type="string">text</item> <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item> </item> </argument> </column> |
Step 2: We have to paste the below code for Class which is defined in the <column> tag.
Path : app\code\Magemonkeys\Holidaylisting\Ui\Component\Listing\Column\HolidayId.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?php namespace Magemonkeys\Holidaylisting\Ui\Component\Listing\Column; use Magento\Framework\UrlInterface; use Magento\Ui\Component\Listing\Columns\Column; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\View\Element\UiComponent\ContextInterface; class HolidayId extends Column { private $urlBuilder; public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, UrlInterface $urlBuilder, array $components = [], array $data = [] ) { $this->urlBuilder = $urlBuilder; parent::__construct($context, $uiComponentFactory, $components, $data); } public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { if (isset($item['holiday_id'])) { $url = $this->urlBuilder->getUrl('holiday/view', ['holiday_id' => $item['holiday_id']]); $link = '<a href="' . $url . '"">' . $item['holiday_id'] . '</a>'; $item['holiday_id'] = $link; } } } return $dataSource; } } |
Now you can see the Id column values are clickable.
[crayon-63d3d9848fa03083219514/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.