Magento2扩展:添加到产品网格的链接
我正在开发magento 2.1.3 ce的扩展。我想在“管理”面板的“产品”网格中添加每个产品的链接: 我想在本专栏中有一个链接,如何将我的扩展名改为有链接而不是纯文本 我的Magento扩展代码(Magento2扩展:添加到产品网格的链接,magento,magento2,Magento,Magento2,我正在开发magento 2.1.3 ce的扩展。我想在“管理”面板的“产品”网格中添加每个产品的链接: 我想在本专栏中有一个链接,如何将我的扩展名改为有链接而不是纯文本 我的Magento扩展代码(app\code\MyCompany\ExampleAdminNewPage\view\adminhtml\ui\u component\product\u listing.xml): 文本 真的 自定义字段2 75 在伪代码中,我想要的是: <column name="{http://m
app\code\MyCompany\ExampleAdminNewPage\view\adminhtml\ui\u component\product\u listing.xml
):
文本
真的
自定义字段2
75
在伪代码中,我想要的是:
<column name="{http://mysite/}"+"sku">
如果URL是内部URL,请尝试以下操作: 步骤1:按如下方式配置列:
<column name="custom_field2" class="MyCompany\ExampleAdminNewPage\Ui\Component\Listing\Column\HTMLLink">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other configurations -->
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
';
$item[$fieldName]=$this->escaper->escapeHtml($html,['a']);
}
}
返回$dataSource;
}
}
如果URL是内部URL,请尝试以下操作:
步骤1:按如下方式配置列:
<column name="custom_field2" class="MyCompany\ExampleAdminNewPage\Ui\Component\Listing\Column\HTMLLink">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other configurations -->
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
';
$item[$fieldName]=$this->escaper->escapeHtml($html,['a']);
}
}
返回$dataSource;
}
}
您可以将其添加为“操作”列。@DhirenVasoya您有一个示例吗?应该如何通过数据源实现它?或者DataModify?您可以将其添加到与actions列相同的列中。@DhirenVasoya您有示例吗?应该如何通过数据源实现它?还是数据修改?
use Magento\Framework\Escaper;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
class HTMLLink extends Column{
protected $escaper;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
Escaper $escaper,
array $components = [],
array $data = []
) {
$this->escaper = $escaper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource){
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as & $item) {
$html = '<a href="some_internal_url" target="_blank">product</a>';
$item[$fieldName] = $this->escaper->escapeHtml($html, ['a']);
}
}
return $dataSource;
}
}