doubushi0031
2016-09-30 13:48
浏览 127
已采纳

自定义网格,在Magento 2的后端进行修改

I’m newbie Magento2 developer. Now I’m making one small module and I’m stuck in one place. I built admin grid with founded example and here is my di.xml:

<preference for="Magento\Catalog\Model\Product" type="Vendor\Module\Model\Product" /> 
<virtualType name="Vendor\Module\Model\ResourceModel\Grid\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">vendor_module</argument>
            <argument name="resourceModel" xsi:type="string">Vendor\Module\Model\ResourceModel\Grid</argument>
        </arguments> 
</virtualType> 
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="grid_record_grid_list_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\Grid\Grid\Collection</item>
            </argument>
        </arguments>
</type>

And also I use layout XML file with hardcoded columns inside:

...
    <column name="customer" >
         <argument name="data" xsi:type="array">
             <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">false</item>
                <item name="label" xsi:type="string" translate="true">Customer</item>
              </item>
          </argument>
    </column>
...

My table has columns like: product id, customer id, price, status

And my questions are:

  • How do I transform customer id to first+last name?
  • Column “status” has 3 different states (0, 1 and 2) - how do I convert them to human-readable words? (undefined, good, bad)
  • How to add to same grid another column for example $price + 10%?

图片转代码服务由CSDN问答提供 功能建议

我是新手Magento2开发者。 我现在正在制作一个小模块而且我被困在一个地方 。 使用建立管理网格 示例,这是我的 di.xml

 &lt; preference for =“Magento \ Catalog \ Model \ Product”type =  “Vendor \ Module \ Model \ Product”/&gt;  
&lt; virtualType name =“Vendor \ Module \ Model \ ResourceModel \ Grid \ Grid \ Collection”type =“Magento \ Framework \ View \ Element \ UiComponent \ DataProvider \ SearchResult”&gt; 
&lt; arguments&gt; 
&lt;  argument name =“mainTable”xsi:type =“string”&gt; vendor_module&lt; / argument&gt; 
&lt; argument name =“resourceModel”xsi:type =“string”&gt; Vendor \ Module \ Model \ ResourceModel \ Grid&lt; / 参数&gt; 
&lt; / arguments&gt;  
&LT; / virtualType&GT;  
&lt; type name =“Magento \ Framework \ View \ Element \ UiComponent \ DataProvider \ CollectionFactory”&gt; 
&lt; arguments&gt; 
&lt; argument name =“collections”xsi:type =“array”&gt; 
  &lt; item name =“grid_record_grid_list_data_source”xsi:type =“string”&gt; Vendor \ Module \ Model \ ResourceModel \ Grid \ Grid \ Collection&lt; / item&gt; 
&lt; / argument&gt; 
&lt; / arguments&gt; 
&lt;  ; / type&gt; 
   
 
 

我还使用带有硬编码列的布局XML文件:

  ...  
&lt; column name =“customer”&gt; 
&lt; argument name =“data”xsi:type =“array”&gt; 
&lt; item name =“config”xsi:type =“array”&gt;  
&lt; item name =“filter”xsi:type =“string”&gt; false&lt; / item&gt; 
&lt; item name =“label”xsi:type =“string”translate =“true”&gt; Customer&lt;  / item&gt; 
&lt; / item&gt; 
&lt; / argument&gt; 
&lt; / column&gt; 
 ... 
   
 
 

我的表有列 喜欢:产品ID,铜 stomer id,price,status

我的问题是:

  • 如何将客户ID转换为第一个+姓氏?
  • “status”有3种不同的状态(0,1和2) - 如何将它们转换为人类可读的单词? (未定义,好,坏)
  • 如何将另一列添加到同一网格中,例如 $ price + 10% \ n
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题