在Magento2后台网格中添加新的列

4.40K 浏览M2插件和模版分享区

在Magento2后台网格中添加新的列

首先,创建和现有网格相同名称的UI_ComponentXML文件。

/app/code/Webkul/Test/view/adminhtml/ui_component/add_column_example.xml,如产品的网格文件是prouct_listing.xml

                                                                 false                     AttributeName                     1                                             


  • name:必须和现有网格的名称相同。
  • class:包含类名,我们在其中定义该列的值。
  • label:用于列的名称,在网格中显示的标题。
  • sortOrder:用于列的排序(好像不管设置多少都会显示在最后面)

然后创建文件 app/code/Max/Test/Ui/Component/Listing/Column/ShowAttrAction.php

getData('name')] = "hello world"; //这是设置你想要展示的值             }         }         return $dataSource;     } }

这个文件用来传递数据,$DataSource返回包含字段值的数组。
$this->getData('name')是传递到网格中的值。

然后刷新缓存,在网格中就可以看到添加的列了。

0