1

my goal is duplicate the default shipments grid in another page from the admin panel.

So far I've created my layout xml:

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

and in the ui_component/vendor_modulename_shipments_grid.xml, I've added this:

<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_modulename_shipments_grid.vendor_modulename_listing_data_source</item>
        </item>
    </argument>
    <settings>
        <buttons>
            <button name="add">
                <url path="*/*/new"/>
                <class>primary</class>
                <label translate="true">My new button</label>
            </button>
        </buttons>
        <spinner>shipments_columns</spinner>
        <deps>
            <dep>vendor_modulename_shipments_grid.vendor_modulename_listing_data_source</dep>
        </deps>
    </settings>
    <dataSource name="vendor_modulename_listing_data_source" component="Magento_Ui/js/grid/provider">
        <settings>
            <updateUrl path="mui/index/render"/>
        </settings>
        <dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="vendor_modulename_listing_data_source">
            <settings>
                <requestFieldName>id</requestFieldName>
                <primaryFieldName>entity_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <columns name="my_column_name">
        <column name="order_increment_id">
            <settings>
                <filter>text</filter>
                 <label translate="true">Order #</label>
            </settings>
        </column>
    </columns>
</listing>

I've didn't want to copy all of the columns from the core file: vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_shipment_grid.xml , so I've added only one : order_increment_id.

So far I am getting this message : Not registered handle vendor_modulename_listing_data_source. Please advice :)

0

You must define which collection is should be used for your data provider in the di.xml, like this:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="vendor_modulename_listing_data_source" xsi:type="string">Vendor\Model\Model\ResourceModel\ModelName\Collection</item>
        </argument>
    </arguments>
 </type>

Because in the collection factory that exception throws in case there no collection related to vendor_modulename_listing_data_source (the $name argument) .

Here is code of the collection factory with that exception:

vendor/magento/framework/View/Element/UiComponent/DataProvider/CollectionFactory.php

/**
 * Class CollectionPool
 */
class CollectionFactory
{
    /**
     * @var Collection[]
     */
    protected $collections;

    /**
     * @var ObjectManagerInterface
     */
    protected $objectManager;

    /**
     * @param ObjectManagerInterface $objectManagerInterface
     * @param array $collections
     */
    public function __construct(
        ObjectManagerInterface $objectManagerInterface,
        array $collections = []
    ) {
        $this->collections = $collections;
        $this->objectManager = $objectManagerInterface;
    }

    /**
     * Get report collection
     *
     * @param string $requestName
     * @return Collection
     * @throws \Exception
     */
    public function getReport($requestName)
    {
        if (!isset($this->collections[$requestName])) {
            throw new \Exception(sprintf('Not registered handle %s', $requestName));
        }
        $collection = $this->objectManager->create($this->collections[$requestName]);
        if (!$collection instanceof Collection) {
            throw new \Exception(sprintf('%s is not of Collection type.', $requestName));
        }
        return $collection;
    }
}
3
  • Cool, Thnx for the quick answer, it works. One more question, if i would like to filter that grid after lets say the order status for the shipment grid. where should I add that filter and how ? Jan 23 '20 at 12:33
  • @AttilaNaghi If I understand you right, you must add a custom filter inside your own collection. If you want to add a column with filter to existing collection (listing) here is my post with example code (but for orders listing). Jan 23 '20 at 13:14
  • thx for helping me out. NO, I don't want another column, I want to filter the shipment collection after the order status . I saw the need to create another post here: magento.stackexchange.com/questions/302026/…. IF you any suggestions ,would be really nice :) thnx Jan 23 '20 at 13:17

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.