1

I am new to Magento and building a custom module. I need to show the admin grid to list data and it’s working fine. Also trying to add mass delete option but that’s not working. Getting below error when I try to delete.

{"0":"Invalid method Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\Document::delete","1":"#0 

Can you please help

Here is my controller

    <?php


namespace Vendor\Module\Controller\Adminhtml\Quote;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Vendor\Module\Model\ResourceModel\QuoteRequest\CollectionFactory;


class MassDelete extends \Magento\Backend\App\Action
{
    /**
     * Mass action Filter
     *
     * @var \Magento\Ui\Component\MassAction\Filter
     */
    protected $_filter;

    /**
     * Collection Factory
     *
     * @var Vendor\Module\Model\ResourceModel\QuoteRequest\CollectionFactory
     */
    protected $_collectionFactory;




    public function __construct(
        Context $context,
        Filter  $filter,
        CollectionFactory   $collectionFactory
    )
    {
        parent::__construct($context);
        $this->_collectionFactory = $collectionFactory;
        $this->_filter  =   $filter;
    }

    public function execute()
    {
      $collection   =   $this->_filter->getCollection($this->_collectionFactory->create());
      $collectionSize = $collection->getSize();
      foreach ($collection as $item){
          $item->delete();
      }

      $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
      $resultRedirect   =   $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
      $resultRedirect->setUrl($this->_redirect->getRefererUrl());
      return $resultRedirect;
    }

}

And here is my Admin ui listing xml

    <?xml version="1.0" encoding="UTF-8"?>
<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">quoterequest_quote_list.quoterequest_quote_list_data_source</item>
            <item name="deps" xsi:type="string">quoterequest_quote_list.quoterequest_quote_list_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 Quote</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="quoterequest_quote_list_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">quoterequest_quote_list_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>

    <listingToolbar name="listing_top">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sticky" xsi:type="boolean">true</item>
            </item>
        </argument>
        <bookmark name="bookmarks"/>
        <columnsControls name="columns_controls"/>
        <exportButton name="export_button"/>
        <filters name="listing_filters" />
        <filterSearch name="fulltext"/>
        <massaction name="listing_massaction">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                </item>
            </argument>
            <action name="delete">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">delete</item>
                        <item name="label" xsi:type="string" translate="true">Delete</item>
                        <item name="url" xsi:type="url" path="quoterequest/quote/massDelete"/>
                        <item name="confirm" xsi:type="array">
                            <item name="title" xsi:type="string" translate="true">Delete item</item>
                            <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                        </item>
                    </item>
                </argument>
            </action>
        </massaction>
        <paging name="listing_paging"/>
    </listingToolbar>

    <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">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="name">
            <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">Name</item>
                </item>
            </argument>
        </column>
        <column name="email">
            <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">Email</item>
                </item>
            </argument>
        </column>
        <column name="created_at" 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">Created</item>
                </item>
            </argument>
        </column>

    </columns>
</listing>

Here 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="George\QuoteRequest\Model\ResourceModel\QuoteRequest\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">george_quoterequest</argument>
            <argument name="resourceModel" xsi:type="string">George\QuoteRequest\Model\ResourceModel\QuoteRequest</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="quoterequest_quote_list_data_source" xsi:type="string">George\QuoteRequest\Model\ResourceModel\QuoteRequest\Collection</item>
            </argument>
        </arguments>
    </type>

</config>
  • share the code of your di.xml file where you create virtual type for this. – Dhiren Vasoya Mar 5 '19 at 14:05
  • @DhirenVasoya- Added the di.xml – GeorgeM Mar 5 '19 at 14:12
0

I have a similar component, the only difference I see is in the provider of the data to be used in the MassAction tag. This is the portion of my xml file, that differs from your:

<massaction name="listing_massaction">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="selectProvider" xsi:type="string">listing.listing.columns.ids</item>
            <item name="indexField" xsi:type="string">id</item>
        </item>
    </argument>
    <action name="delete">
| improve this answer | |
0

You need to change your mass listing code into xml file like this.

<massaction name="listing_massaction">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">

<item name="selectProvider" xsi:type="string">quoterequest_quote_list.quoterequest_quote_list.quoterequest_quote_list_columns.ids</item>
              <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
              <item name="indexField" xsi:type="string">id</item>
                </item>
            </argument>
            <action name="delete">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">delete</item>
                        <item name="label" xsi:type="string" translate="true">Delete</item>
                        <item name="url" xsi:type="url" path="quoterequest/quote/massDelete"/>
                        <item name="confirm" xsi:type="array">
                            <item name="title" xsi:type="string" translate="true">Delete item</item>
                            <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                        </item>
                    </item>
                </argument>
            </action>
        </massaction>
| improve this answer | |
  • I try what you said but still showing same error – GeorgeM Mar 5 '19 at 15:32
0

Resolve this issue and updated my di.xml file

    <virtualType name="Vendor\Module\Model\ResourceModel\QuoteRequest\**Grid**\Collection"

<item name="quoterequest_quote_listing_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\QuoteRequest\**Grid**\Collection</item>
| 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.