InsideDarkWeb.com

Admin GRID Not Showing Data with ui_component

I am creating a custom module to show some listing data submitted from frontend to database after save to show it in admin GRID. Saving data is working fine but listing in GRID using ui_component is not working.

Changed the router and menu file a bit and now i am getting this error on the page in admin where grid is.

Exception #0 (Exception): Warning: class_implements(): Class ListsGridDataProvider does not exist.

my Controller in CompanyModuleControllerAdminthtmlTestimonial

<?php

namespace ApriljuneTestimonialControllerAdminhtmlTestimonial;

class Testimonial extends MagentoBackendAppAction
 {
protected $resultPageFactory = false;

public function __construct(
    MagentoBackendAppActionContext $context,
    MagentoFrameworkViewResultPageFactory $resultPageFactory
)
{
    parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
}

public function execute()
{
    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->prepend((__('Testimonial')));

    return $resultPage;
}

protected function _isAllowed()
{
    return true;
}

}

My router is

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="apriljune_testimonial" frontName="apriljune_testimonial">
  <module name="Apriljune_Testimonial" before="Magento_Backend" />
</route>
</router>
</config>

my menu.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
    <add id="Apriljune_Testimonial::testimonial" title="Apriljune Testimonial" resource="Apriljune_Testimonial::testimonial" module="Apriljune_Testimonial"  sortOrder="20"/>
    
    <add id="Apriljune_Testimonial::testimoniallist" title="Testimonial List" resource="Apriljune_Testimonial::apriljune_testimonial_testimonial" parent="Apriljune_Testimonial::testimonial" action="apriljune_testimonial/testimonial/testimonial" module="Apriljune_Testimonial" sortOrder="20"/>
 </menu>
  </config>

Model is:

<?php

 namespace ApriljuneTestimonialModel;

 use MagentoFrameworkModelAbstractModel;

 class Testimonial extends MagentoFrameworkModelAbstractModel {


 protected function _construct() {
    $this->_init('ApriljuneTestimonialModelResourceModelTestimonial');
  }

}

Resource Model:

<?php

 namespace ApriljuneTestimonialModelResourceModel;

 use MagentoFrameworkModelResourceModelDbAbstractDb;

 class Testimonial extends AbstractDb
 {

public function __construct(
    MagentoFrameworkModelResourceModelDbContext $context
)
{
    parent::__construct($context);
}

/**
 * Initialize resource model
 *
 * @return void
 */
protected function _construct()
{
    $this->_init('apriljune_testimonial', 'id');
}
}

Collection File in ApriljuneTestimonialModelResourceModelTestimonial

<?php

namespace ApriljuneTestimonialModelResourceModelTestimonial;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use ApriljuneTestimonialModelTestimonial as Model;
use ApriljuneTestimonialModelResourceModelTestimonial as ResourceModel;

class Collection extends AbstractCollection{

protected $_idFieldName = 'id';
protected $_eventPrefix = 'apriljune_testimonial_testimonial_collection';
protected $_eventObject = 'testimonial_collection';

protected function _construct()
{
    $this->_init(Model::class, ResourceModel::class);
}
}

my di.xml file is like:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="apriljune_testimonial_testimonial_listing_data_source" xsi:type="string">ApriljuneTestimonialModelResourceModelTestimonialCollection</item>
        </argument>
    </arguments>
</type>
<virtualType name="ApriljuneTestimonialModelResourceModelTestimonialCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
    <arguments>
        <argument name="mainTable" xsi:type="string">apriljune_testimonial</argument>
        <argument name="resourceModel" xsi:type="string">ApriljuneTestimonialModelResourceModelTestimonial</argument>
    </arguments>
</virtualType>

admin layout file for declaring ui_component like follows:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
    <referenceContainer name="content">
        <uiComponent name="apriljune_testimonial_testimonial_listing"/>
    </referenceContainer>
</body>

ui_component have the following code in it,

<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">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source</item>
        <item name="deps" xsi:type="string">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source</item>
    </item>
    <item name="spinner" xsi:type="string">spinner_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" xsi:type="string" translate="true">Add New Testimonial</item>
            <item name="class" xsi:type="string">primary</item>
            <item name="url" xsi:type="string">*/*/new</item>
        </item>
    </item>
</argument>
<dataSource name="apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">MagentoFrameworkViewElementUiComponentDataProviderDataProvider</argument>
        <argument name="name" xsi:type="string">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                <item name="update_url" xsi:type="url" path="mui/index/render"/>
                <item name="storageConfig" xsi:type="array">
                    <item name="indexField" xsi:type="string">id</item>
                </item>
            </item>
        </argument>
    </argument>
</dataSource>
<columns name="spinner_columns">
    <selectionsColumn name="id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="resizeEnabled" xsi:type="boolean">false</item>
                <item name="resizeDefaultWidth" xsi:type="string">55</item>
                <item name="indexField" xsi:type="string">id</item>
            </item>
        </argument>
    </selectionsColumn>
    <column name="id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">textRange</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="label" xsi:type="string" translate="true">ID</item>
            </item>
        </argument>
    </column>

    <column name="created_at" class="MagentoUiComponentListingColumnsDate">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">dateRange</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                <item name="dataType" xsi:type="string">date</item>
                <item name="label" xsi:type="string" translate="true">Created</item>
            </item>
        </argument>
    </column>
    <column name="modified_at" class="MagentoUiComponentListingColumnsDate">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">dateRange</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                <item name="dataType" xsi:type="string">date</item>
                <item name="label" xsi:type="string" translate="true">Modified</item>
            </item>
        </argument>
    </column>
</columns>
</listing>

and DB schema i am using is declarative one like this:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

<table name="apriljune_testimonial" resource="default" comment="Table for Apriljune Testimonial Main">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="status" nullable="false"/>
    <column xsi:type="date" name="created_at"  nullable="false"/>
    <column xsi:type="date" name="modified_at"  nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
</table>

<table name="apriljune_testimonial_author" resource="default" comment="Table for Apriljune Testimonial Author">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Constraint"/>
    <column xsi:type="varchar" name="author_name" nullable="false"/>
    <column xsi:type="varchar" name="author_email" nullable="false"/>
    <column xsi:type="varchar" name="author_company" nullable="false"/>
    <column xsi:type="varchar" name="author_job_title" nullable="false"/>
    <column xsi:type="varchar" name="author_city"  nullable="false"/>
    <column xsi:type="varchar" name="author_image" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_AUTHOR_TESTIMONIAL_ID"
                table="apriljune_testimonial_author" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

<table name="apriljune_testimonial_social" resource="default"
       comment="Table for Apriljune Testimonial Social Profile Information">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Constraint"/>
    <column xsi:type="varchar" name="facebook_url" nullable="false"/>
    <column xsi:type="varchar" name="linkedin_url" nullable="false"/>
    <column xsi:type="varchar" name="twitter_url" nullable="false"/>
    <column xsi:type="varchar" name="youtu_url" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_SOCIAL_TESTIMONIAL_ID"
                table="apriljune_testimonial_social" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

<table name="apriljune_testimonial_content" resource="default" comment="Table for Apriljune Testimonial Content">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Id from Author Table"/>
    <column xsi:type="varchar" name="testimonial_title" nullable="false"/>
    <column xsi:type="varchar" name="testimonial_description" nullable="false"/>
    <column xsi:type="varchar" name="testimonial_rating_number" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_CONTENT_TESTIMONIAL_ID"
                table="apriljune_testimonial_content" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

</schema>

as i have said above frontend form submission is really working fine and saving the data into multiple tables , but i am facing an issue with the admin data it is still showing me the blank page no grid is creating but just showing the Title there, please have a look at the code provided and identify the mistakes or any possible solution.

Thanks in advance.

Screenshot:
enter image description here

Magento Asked by shoaib Munir on October 2, 2021

1 Answers

One Answer

you can try with below code in your di.xml file:

di.xml

<!-- Create our type GridDataProvider -->
      <virtualType name="TestimonialGridDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
            <arguments>
                <argument name="collection" xsi:type="object" shared="false">ApriljuneTestimonialModelResourceModelTestimonialCollection</argument>
                <argument name="filterPool" xsi:type="object" shared="false">TestimonialGridFilterPool</argument>
            </arguments>
     </virtualType>
        
     <virtualType name="TestimonialGridFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
            <arguments>
                <argument name="appliers" xsi:type="array">
                    <item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
                    <item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
                </argument>
            </arguments>
     </virtualType>

    <type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="apriljune_testimonial_testimonial_listing_data_source" xsi:type="string">ApriljuneTestimonialModelResourceModelTestimonialCollection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="ApriljuneTestimonialModelResourceModelTestimonialCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">apriljune_testimonial</argument>
            <argument name="resourceModel" xsi:type="string">ApriljuneTestimonialModelResourceModelTestimonial</argument>
        </arguments>
    </virtualType>

Correct answer by Hitesh Balpande on October 2, 2021

Add your own answers!

Related Questions

Magento 2.4 PWA : How to setup with LEMP stack using Docker

0  Asked on October 1, 2021 by saditha-udayanga

         

Remove product attribute automatically

2  Asked on October 1, 2021

 

Error while saving custom fields on place order

0  Asked on March 6, 2021 by pramod

 

Watermark Category Images with Brand Logo

1  Asked on February 26, 2021 by ijeep

       

Issue With Displaying Gallery Widget

1  Asked on February 24, 2021 by magento_learner

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.