I have created a UI component to represent the data in my custom eav model. But it didn't work at all. The spinning animation didn't disappear and my page looks like this
I checked all the log file and it didn't have any php error. I checked console tab in my browser too and it didn't have any javascript error.
This is my entity table
enter image description here
This is my ui component code
<?xml version="1.0" ?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_vendor_index.vendor_grid_data_source</item>
<item name="deps" xsi:type="string">vendor_vendor_index.vendor_grid_data_source</item>
</item>
<item name="spinner" xsi:type="string">vendor_vendor_columns</item>
<item name="buttons" xsi:type="array">
<item name="add" xsi:type="array">
<item name="name" xsi:type="string">add</item>
<item name="label" translate="true" xsi:type="string">Add new Vendor</item>
<item name="class" xsi:type="string">primary</item>
<item name="url" xsi:type="string">*/*/new</item>
</item>
</item>
</argument>
<dataSource name="vendor_grid_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
<argument name="name" xsi:type="string">vendor_grid_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">entity_id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="update_url" path="mui/index/render" xsi:type="url"/>
</item>
</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
</item>
</argument>
</dataSource>
<columns name="vendor_vendor_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</argument>
</selectionsColumn>
<column name="entity_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
<item name="filter" xsi:type="string">text</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" translate="true" xsi:type="string">ID</item>
<item name="dataType" xsi:type="string">text</item>
</item>
</argument>
</column>
</columns>
</listing>
This is my di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="{Namespace}\{ModuleName}\Model\ResourceModel\Vendor\Grid\Collection"
type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">namespace_vendor_entity</argument>
<argument name="resourceModel" xsi:type="string">{Namespace}\{ModuleName}\Model\ResourceModel\Vendor\Collection</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="vendor_grid_data_source" xsi:type="string">{Namespace}\{ModuleName}\Model\ResourceModel\Vendor\Grid\Collection</item>
</argument>
</arguments>
</type>
</config>
This is my layout code. The ui component file name is vendor_listing.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="formkey"/>
<body>
<referenceContainer name="content">
<uiComponent name="vendor_listing"/>
</referenceContainer>
</body>
</page>
Please tell me why it's not working and how can I debug this?
1 Answer 1
Please make path to resourcemodel instead of collection:
write {Namespace}{ModuleName}\Model\ResourceModel\Vendor instead of {Namespace}{ModuleName}\Model\ResourceModel\Vendor\Collection
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="{Namespace}\{ModuleName}\Model\ResourceModel\Vendor\Grid\Collection"
type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">namespace_vendor_entity</argument>
<argument name="resourceModel" xsi:type="string">{Namespace}\{ModuleName}\Model\ResourceModel\Vendor</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="vendor_grid_data_source" xsi:type="string">{Namespace}\{ModuleName}\Model\ResourceModel\Vendor\Grid\Collection</item>
</argument>
</arguments>
</type>
-
it didn't work after I changed it to
{Namespace}{ModuleName}\Model\ResourceModel\Vendorthanhdv2811– thanhdv28112018年07月17日 11:43:26 +00:00Commented Jul 17, 2018 at 11:43 -
Have you check after clearing cache and cookie or after removing generated folder?Rutvee Sojitra– Rutvee Sojitra2018年07月17日 11:47:30 +00:00Commented Jul 17, 2018 at 11:47
-
Yes. I run the command
setup:upgrade,cache:flusandcache:cleanbut it's still the samethanhdv2811– thanhdv28112018年07月17日 11:54:25 +00:00Commented Jul 17, 2018 at 11:54 -
@thanhdv2811 Can you please post your layout file code hereRutvee Sojitra– Rutvee Sojitra2018年07月17日 11:59:27 +00:00Commented Jul 17, 2018 at 11:59
-
1you have to replace vendor_vendor_index.vendor_grid_data_source with vendor_listing.vendor_grid_data_sourceRutvee Sojitra– Rutvee Sojitra2018年07月19日 05:12:54 +00:00Commented Jul 19, 2018 at 5:12