4

I have an extra column in my Magento 2 admin order grid, with a column with external urls. This is working well (I see an overview of al my hyperlinks).

But when I click on a url, I go to the order detail page instead of my external url. I suppose, this is due the "data-bind" Knockout code. How can I make working urls? Can I disable the onclick events for a single column?

(tricks like css z-index:999 are not working...)

Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
asked Aug 22, 2017 at 10:17

3 Answers 3

15

If You are using custom class for rendering column ( for example <column name="link" class="My\Module\Ui\Component\Listing\Column\Link">) which convert your column value to link html along with cells html js ui component (<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>) you can disable default action which fires on grid row click by adding to your column config item:

<item name="fieldAction" xsi:type="boolean">false</item>

answered Feb 21, 2018 at 11:51
1
  • Thanks. It worked for me. I missed to add <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item> Commented Sep 10, 2018 at 10:22
7

I had the same issue for UI grid and resolved it by rewriting component for current cell:

Vendor/MyModule/view/adminhtml/ui_component/my_grid_listing.xml file:

<column name="link">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="label" xsi:type="string" translate="true">Link</item>
 <item name="component" xsi:type="string">Vendor_MyModule/js/grid/cells/link</item>
 <item name="sortOrder" xsi:type="number">50</item>
 <item name="sortable" xsi:type="boolean">false</item>
 <item name="disableAction" xsi:type="boolean">true</item>
 </item>
 </argument>
</column>

and disabled function getFieldHandler() in:

Vendor/MyModule/view/adminhtml/web/js/grid/cells/link.js

define([
 'Magento_Ui/js/grid/columns/column'
 ],
 function (Column) {
 'use strict';
 return Column.extend({
 defaults: {
 bodyTmpl: 'Vendor_MyModule/grid/cells/link',
 },
 getFieldHandler: function (record) {
 return false;
 }
 });
 }
);

Template:

Vendor/MyModule/view/adminhtml/web/template/grid/cells/link.html

<a class="action-menu-item"
 text="$col.getLabel($row())"
 attr="href: $col.getLabel($row())"
 target="_blank"/>
Siarhey Uchukhlebau
16.2k11 gold badges57 silver badges89 bronze badges
answered Jan 15, 2018 at 14:51
1
  • It's not working Commented Dec 10, 2018 at 10:53
1

You can create Render File for clickable that URL.

URL.php inside Renderer Folder

<?php
namespace Namespace\Modulename\Block\Adminhtml\Module\Edit\Tab\Renderer;
use Magento\Framework\DataObject;
class Url extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
 public function render(DataObject $row)
 {
 $rowId = $row->getId();
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
 $baseUrl = $storeManager->getStore()->getBaseUrl();
 return '<a target="_blank" href="'.$baseUrl.'">'.$baseUrl.'</a>';
 }
}

And inside your Grid.php

protected function _prepareColumns()
{
 $this->addColumn('id', [
 'header' => __('URL'),
 'index' => 'id',
 'renderer' => 'Namespace\Modulename\Block\Adminhtml\Module\Edit\Tab\Renderer\Url'
 ]);
}

Your URL will be clickable and open that URL in new tab. Hope it helps :)

answered Aug 22, 2017 at 13:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.