In Magento 2.1.* target _blank is not working
Following file is responsible to render action in admin UI component Grid
vendor/magento/module-ui/view/base/web/templates/grid/cells/actions.html
Change:
attr="href: $action().href" to attr="target: $col.getTarget($action()), href: $action().href"
For action dropdown change:
attr="href: $action().href, 'data-action': 'item-' + $action().index" to attr="target: $col.getTarget($action()), href: $action().href, 'data-action': 'item-' + $action().index"
Or replace below code in vendor/magento/module-ui/view/base/web/templates/grid/cells/actions.html:
<a class="action-menu-item" if="$col.isSingle($row()._rowIndex)" repeat="foreach: $col.getVisibleActions($row()._rowIndex), item: '$action'" click="$col.getActionHandler($action())" text="$action().label" attr="href: $action().href"/> <div class="action-select-wrap" if="$col.isMultiple($row()._rowIndex)" collapsible> <button class="action-select" translate="'Select'" toggleCollapsible/> <ul class="action-menu" css="_active: $collapsible.opened"> <li repeat="foreach: $col.getVisibleActions($row()._rowIndex), item: '$action'"> <a class="action-menu-item" click="$col.getActionHandler($action())" text="$action().label" attr="href: $action().href, 'data-action': 'item-' + $action().index"/> </li> </ul> </div>
Replace with below code
<a class="action-menu-item" if="$col.isSingle($row()._rowIndex)" repeat="foreach: $col.getVisibleActions($row()._rowIndex), item: '$action'" click="$col.getActionHandler($action())" text="$action().label" attr="target: $col.getTarget($action()), href: $action().href"/> <div class="action-select-wrap" if="$col.isMultiple($row()._rowIndex)" collapsible> <button class="action-select" translate="'Select'" toggleCollapsible/> <ul class="action-menu" css="_active: $collapsible.opened"> <li repeat="foreach: $col.getVisibleActions($row()._rowIndex), item: '$action'"> <a class="action-menu-item" click="$col.getActionHandler($action())" text="$action().label" attr="target: $col.getTarget($action()), href: $action().href, 'data-action': 'item-' + $action().index"/> </li> </ul> </div>
Add below function to vendor/magento/module-ui/view/base/web/js/grid/columns/actions.js which is already there in Magento 2.2
/** * Returns target of action if it's been set. * * @param {Object} action - Action object. * @returns {String} */ getTarget: function (action) { if (action.target) { return action.target; } return '_self'; },
Now Use : #File: Vendor/Module/Ui/Component/Listing/Column/PageActions.php
//... $item[$name]['edit'] = [ 'href' => $this->urlBuilder->getUrl($this->editUrl, ['page_id' => $item['page_id']]), 'target' => '_blank', 'label' => __('Edit') ];
Now, Target _blank will work for Magento 2.1.* versions