2

I have been trying to create a grid list for my custom module. All code part is done and the grid not displayed. Reviewed the code many times but I couldn't find the issue. enter image description here

Here is my code:

Test\TestWorkflow\Controller\Adminhtml\Departmentcodes\DepartmentListing.php

<?php
namespace Test\TestWorkflow\Controller\Adminhtml\Departmentcodes;

class DepartmentListing extends \Magento\Backend\App\Action
{
    protected $resultPageFactory = false;
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ){
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

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

Test\TestWorkflow\view\adminhtml\layout\purchaseorder_departmentcodes_departmenlisting.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceContainer name="content">
        <uiComponent name="test"/>
    </referenceContainer>
  </body>
</page>

Test\TestWorkflow\view\adminhtml\ui_components\test.xml

<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">test.test_departmentlisting_data_source</item>
            <item name="deps" xsi:type="string">test.test_departmentlisting_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</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string"></item>
            </item>
        </item>
    </argument>
    <dataSource name="test_departmentlisting_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">test_departmentlisting_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">
        <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="code">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">Code</item>
                </item>
            </argument>
        </column>
        <column name="description">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">Description</item>
                </item>
            </argument>
        </column>
        <!-- <actionsColumn name="actions" class="Test\TestOrderWorkflow\Ui\Component\Listing\Grid\Column\DepartmentCodes\Action">
           <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">107</item>
                   <item name="indexField" xsi:type="string">id</item>
               </item>
           </argument>
       </actionsColumn> -->
    </columns>
</listing>

Test\TestWorkflow\etc\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="Test\TestWorkflow\Model\ResourceModel\DepartmentCodes\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">test_dept_code</argument>
            <argument name="resourceModel" xsi:type="string">Test\TestWorkflow\Model\ResourceModel\DepartmentCodes</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="test_departmentlisting_data_source" xsi:type="string">
                    Test\TestWorkflow\Model\ResourceModel\DepartmentCodes\Grid\Collection
                </item>
            </argument>
        </arguments>
    </type>
</config>

1 Answer 1

1

Based on the code you've provided, it seems that there are a few things that may be causing the grid to not display.

  1. Make sure that your DataProvider class is correctly set up and that it is returning the data for the grid.
  2. Check the primary and request field names in the DataProvider argument, make sure that they match the field names in your database table.
  3. Make sure that the path in the update_url item of the DataProvider config matches the path of the controller action that is responsible for providing the data for the grid.
  4. Make sure that your column names match the field names in your database table, and that the column component is set up correctly.
  5. Verify that your grid is using the correct data source, that is test_departmentlisting_data_source.
  6. Make sure that you have cleared the cache, if not run php bin/magento cache:clean

It might be helpful to check the browser's developer console for any error messages that could give more insight into what is causing the grid to not display.

Also, it's good to check the browser's network tab, check if any request is being made to the controller, or not.

Please let me know if you need further assistance, and providing more context about your module and data source would help to give more accurate answers.

Here's the detailed guide to create admin grid using UI Component: https://www.rohanhapani.com/magento-2-create-ui-component-grid-and-form/ (I'm highly recommended to go through once)

Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.