0

I've been fighting with a problem for the last couple of days (I'm new to M2), so I hope you can help me further in this task to find a solution. I've been following this guide: https://www.mageplaza.com/magento-2-module-development/create-admin-grid-magento-2.html

My di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="coolrunner_shipping_labels_listing_data_source" xsi:type="string">CoolRunner\Shipping\Model\ResourceModel\Labels\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="CoolRunner\Shipping\Model\ResourceModel\Labels\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">coolrunner_shipping_labels</argument>
            <argument name="resourceModel" xsi:type="string">CoolRunner\Shipping\Model\ResourceModel\Labels</argument>
        </arguments>
    </virtualType>
</config>

My controller (Index.php)

class Index 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((__('Labels')));

        return $resultPage;
    }
}

My Layout file

<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="coolrunner_shipping_labels_listing"/>
        </referenceContainer>
    </body>
</page>

My ui_component file

<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">coolrunner_shipping_labels_listing.coolrunner_shipping_labels_listing_data_source</item>
            <item name="deps" xsi:type="string">coolrunner_shipping_labels_listing.coolrunner_shipping_labels_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 Post</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="nameOfDataSource">
        <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">coolrunner_shipping_labels_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">post_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">post_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="spinner_columns">
        <selectionsColumn name="ids">
            <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">post_id</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="post_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="package_number">
            <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">Pakkenummer</item>
                </item>
            </argument>
        </column>
        <column name="date" class="Magento\Ui\Component\Listing\Columns\Date">
            <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">Oprettet</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

The result is just a blank page with the title "Labels". It doesn't add any grid to the page? Do you have any idea where the problem could be? I hope you guys can help me with this.

Result page

0
   <dataSource name="coolrunner_shipping_labels_listing_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">coolrunner_shipping_labels_listing_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">post_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">post_id</item>
                </item>
            </item>
        </argument>
    </argument>
</dataSource>

Everything looks ok except<dataSource name="nameOfDataSource">

| improve this answer | |
  • Hi @sudo55 , i changed my dataSource in ui_component to that you send, but still get same result. You know howcome? It doesnt even show an empty table. Its just blank. – Kevin Steen Hansen Jun 25 at 12:53
  • okay realod the page, open the network in inspect and see if there is error? – sudo55 Jun 25 at 12:58
  • No errors in network tab :/ Tell me if there is any additionel information you need :) – Kevin Steen Hansen Jun 25 at 13:00
  • And if try using the other method i get told its deprecated. – Kevin Steen Hansen Jun 26 at 6:17
0

Problem solved.

My route was set wrong.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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