[Solved] How to use custom collection class as data provider in Magento 2 for grid?

amitshree Asks: How to use custom collection class as data provider in Magento 2 for grid?
I have added a custom data provider in Magento 2. I can see the data in grid. Though when I try to export the data in csv format, it says

Error: Call to a member function setCurrentPage() on null

Below is the code I am using in ui component file

<dataSource name="vendor_deliveryslotreport_index_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">VendorDeliverySlotReportModelResourceModelDeliverySlotReportCustomCollection</argument>
            <argument name="name" xsi:type="string">vendor_deliveryslotreport_index_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">op_order_id</argument>
            <argument name="requestFieldName" xsi:type="string">op_order_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">op_order_id</item>

I have commented all the code of di.xml file as I have added class directly in above file and believe it should work.

And here is my custom collection file.


namespace VendorDeliverySlotReportModelResourceModelDeliverySlotReport;

use MagentoFrameworkAppResourceConnection;
use MagentoUiDataProviderAbstractDataProvider;
use VendorGroceryOrdersModelResourceModelOnlinepartnersModelCollectionFactory;

class CustomCollection extends AbstractDataProvider

    protected $collection;
    protected $addFieldStrategies;
    protected $addFilterStrategies;
    protected $resourceConnection;
    protected $dataCollectionFactory;

    public function __construct(
        CollectionFactory $collectionFactory,
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
        $this->collection = $collectionFactory->create();

    public function getCollection()
        return $this->collection;

    public function getData()
        if (!$this->getCollection()->isLoaded()) {
        return $this->getCollection()->toArray();

what I need to add so that I should be able to export the data in csv as well without getting error Call to a member function setCurrentPage() ?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.