Hi everybody,
hope you can help me solving this problem. I can't see the problem.
I created an extension to display a custom admin grid in my administration backend. Everything works fine. All data is displayed in the grid. Now I want to delete all entries in this table with a mass delete action. So I created a controller to do this. The execute method in my class looks like this:
$collection = $this->_filter->getCollection($this->_codeBlocksFactory->create()); foreach ($collection as $item) { $item->delete(); }
Every time when I try to execute these I get the following exception:
string(87) "Invalid method Magento\Framework\View\Element\UiComponent\DataProvider\Document::delete"
I actually don't know where the problem occures. I don't understand why my returning object is not from the model type I created for this extension.
Maybe someone of you have an idea to solve this problem?
Thanks a lot!
Michael
CRUD model methods are deprecated, use Repositories instead.
Check the di.xml
virtual type has to have Grid\ before Collection
And item the same inside the the argument
…….\Grid\Collection
I had same issue to resolve this issue you need to make change in di.xml file.
In virtual type: Check bold part you need to add that before collection.
<virtualType name="Company\Module\Model\ResourceModel\Tracks\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
Same in type:
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="company_module_listing_data_source" xsi:type="string">Company\Module\Model\ResourceModel\Tracks\Grid\Collection</item>
</argument>
</arguments>
</type>
You need to write Grid before collection at both place to fix the issue.
I hope this helps.
Thanks,
Work for me
Thanks it's solve my problem
thanks
Thanks a lot, this solution works!