I have created a custom UI component grid in admin. But there is no link on grid rows.

How to add URL to rows in a custom UI component grid in admin?


For adding Anchor in uicomponent grid in admin, your column must look like below.

    <column name="order_id" class="Your\Module\Ui\Component\Listing\Column\MyOrder">
           <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Order Id</item>

In Your Your\Module\Ui\Component\Listing\Column\MyOrder File.

You can get value of that particuler cell in file where You can manipulate value to specific html. like i did below.

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\UrlInterface;

class MyOrder extends Column {

    protected $escaper;

    protected $_urlBuilder;
    protected $systemStore;
    protected $productFactory;
    protected $_orderRepo;

    public function __construct(
        UrlInterface $urlBuilder, 
        ContextInterface $context, 
        UiComponentFactory $uiComponentFactory,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepo,
        Escaper $escaper,
        array $components = [], array $data = []
    ) {
        $this->_orderRepo = $orderRepo;
        $this->_urlBuilder = $urlBuilder;
        $this->escaper = $escaper;
        parent::__construct($context, $uiComponentFactory, $components, $data);

    public function prepareDataSource(array $dataSource) {

        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                $incrementId = $this->_orderRepo->get($item['order_id'])->getIncrementId();
                $url = $this->_urlBuilder->getUrl("sales/order/view", array('order_id' => $item['order_id']));
                $item['order_id'] = "<a href='" . $url . "' target='_blank' >" . $incrementId . "</a>";

        return $dataSource;

  • I am not talking about the column, I need URL on the row. – Anshu Mishra Feb 23 '18 at 7:15
  • on whole row? @AnshuMishra – Rizwan Khan Feb 23 '18 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.