【问题标题】:Display a custom field with Rendered in Product Grid UI Component in Magento 2在 Magento 2 的 Product Grid UI 组件中显示带有渲染的自定义字段
【发布时间】:2016-06-13 06:34:41
【问题描述】:

我想在产品网格 UI 组件中添加一个自定义字段,它将显示一些将从产品自定义选项中获取的文本。

我尝试了很多解决方案,但都是针对其他网格系统而不是 Magento 2 产品网格 UI 组件。我找到了如何添加自定义图像,但我想显示我在产品网格 UI 组件中的自定义选项之一。请帮忙

【问题讨论】:

  • 请分享您的代码
  • @WicherVisser :我什么都没写。请告诉我该怎么做。

标签: magento2


【解决方案1】:

据我所知,您希望将自定义字段添加到您的产品网格中。您可以通过创建具有网格的自定义操作来做到这一点。 在您的网格类中添加列时添加您的渲染,如下所示

$this->addColumn( 'coulmnName', [ 'header' => __('Title'), 'renderer'=>'\path\to\your\ClassName', ] );

在您的班级中添加您的东西以呈现并返回任何数据,如下所示

namespace your\class\path;

class ClassName extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{

    public function __construct(
        \Magento\Backend\Block\Context $context,
        array $data = []
    )
    {
        parent::__construct($context, $data);
    }
    public function render(\Magento\Framework\DataObject $row)
    {
        //get any data from tour current Grid Column
        $data = $row->getCoulmnName();
        // do your stuff
        return $anyData;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 2014-01-19
    • 2021-02-11
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多