0

I have created a custom grid with following di.xml

di.xml

<preference for="\Magento\Customer\Controller\Adminhtml\Index\InlineEdit" type="Namespace\Modulename\Controller\Adminhtml\Index\InlineEdit" />

 <type name="\Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="school_district_listing_data_source" xsi:type="string">Namespace\Modulename\Model\ResourceModel\Agencyzipmapping\Grid\Collection</item>
        </argument>
    </arguments>
</type>

<type name="Namespace\Modulename\Model\ResourceModel\Agencyzipmapping\Grid\Collection">
    <arguments>
        <argument name="mainTable" xsi:type="string">agency_zipcode_mapping</argument>
        <argument name="resourceModel" xsi:type="string">Namespace\Modulename\Model\ResourceModel\Agencyzipmapping</argument>
    </arguments>
</type>

Whenever I activate / enable my module, other grids in admin panel show following error: Not registered handle

I tried changing type to virtual type as mentioned over here. That didn't work out.

1
<?php
namespace 
Namespace\ModuleName\Model\ResourceModel\Agencyzipmapping\Grid;

use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Api\Search\AggregationInterface;
use Psr\Log\LoggerInterface;
use Ecs\Addressautofill\Model\ResourceModel\Agencyzipmapping\Collection as schoolCollection;

class Collection extends schoolCollection implements SearchResultInterface
{
/**
 * Aggregations
 * 
 * @var AggregationInterface
 */
protected $aggregations;

/**
 * constructor
 * 
 * @param EntityFactoryInterface $entityFactory
 * @param LoggerInterface $logger
 * @param FetchStrategyInterface $fetchStrategy
 * @param EventManagerInterface $eventManager
 * @param string $mainTable
 * @param string $eventPrefix
 * @param string $eventObject
 * @param string $resourceModel
 * @param AdapterInterface $connection
 * @param AbstractDb $resource
 * @param $model
 */
public function __construct(
    EntityFactoryInterface $entityFactory,
    LoggerInterface $logger,
    FetchStrategyInterface $fetchStrategy,
    EventManagerInterface $eventManager,
    $mainTable,
    $eventPrefix,
    $eventObject,
    $resourceModel,
    AdapterInterface $connection = null,
    AbstractDb $resource = null,
    $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document'
)
{
    parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
    $this->_eventPrefix = $eventPrefix;
    $this->_eventObject = $eventObject;
    $this->_init($model, $resourceModel);
    $this->setMainTable($mainTable);
}


/**
 * @return AggregationInterface
 */
public function getAggregations()
{
    return $this->aggregations;
}

/**
 * @param AggregationInterface $aggregations
 * @return $this
 */
public function setAggregations($aggregations)
{
    $this->aggregations = $aggregations;
}


/**
 * Retrieve all ids for collection
 * Backward compatibility with EAV collection
 *
 * @param int $limit
 * @param int $offset
 * @return array
 */
public function getAllIds($limit = null, $offset = null)
{
    return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
}

/**
 * Get search criteria.
 *
 * @return \Magento\Framework\Api\SearchCriteriaInterface|null
 */
public function getSearchCriteria()
{
    return null;
}

/**
 * Set search criteria.
 *
 * @param SearchCriteriaInterface $searchCriteria
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setSearchCriteria(SearchCriteriaInterface $searchCriteria = null)
{
    return $this;
}

/**
 * Get total count.
 *
 * @return int
 */
public function getTotalCount()
{
    return $this->getSize();
}

/**
 * Set total count.
 *
 * @param int $totalCount
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setTotalCount($totalCount)
{
    return $this;
}

/**
 * Set items list.
 *
 * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setItems(array $items = null)
{
    return $this;
}

protected function _initSelect() 
{
    $this->addFilterToMap('id', 'city_master.id');
    $this->addFilterToMap('id', 'agency_master.id');
    $this->addFilterToMap('id', 'zipcode_master.id');

    parent::_initSelect();

    $cityMasterTable = $this->getTable('city_master');
    $this->getSelect()->join($cityMasterTable, 'main_table.city_id = city_master.id', ['city_name']);

    $agencyMasterTable = $this->getTable('agency_master');
    $this->getSelect()->join($agencyMasterTable, 'main_table.agency_id = agency_master.id', ['agency_name']);

    $zipcodeMasterTable = $this->getTable('zipcode_master');
    $this->getSelect()->join($zipcodeMasterTable, 'main_table.zipcode_id = zipcode_master.id', ['zipcode']);

    $stateTable = $this->getTable('directory_country_region');
    $this->getSelect()->join($stateTable, 'main_table.state_id = directory_country_region.region_id', ['default_name']);
}

}

0

replace di.xml below code

<type name="Namespace\Modulename\Model\ResourceModel\Agencyzipmapping\Grid\Collection">
    <arguments>
        <argument name="mainTable" xsi:type="string">agency_zipcode_mapping</argument>
        <argument name="resourceModel" xsi:type="string">Namespace\Modulename\Model\ResourceModel\Agencyzipmapping</argument>
    </arguments>
</type>

to

<virtualType name="Namespace\Modulename\Model\ResourceModel\Agencyzipmapping\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">agency_zipcode_mapping</argument>
            <argument name="resourceModel" xsi:type="string">Namespace\Modulename\Model\ResourceModel\Agencyzipmapping</argument>
        </arguments>
    </virtualType>



    <virtualType name="MyGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="MyGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Namespace\Modulename\Model\ResourceModel\Agencyzipmapping\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">MyGirdFilterPool</argument>
        </arguments>
    </virtualType>
  • Thanks for reply, i have tried this method but isnt working and i also moved my etc/adminhtml/di.xml to etc/di.xml – Ritesh Shukla Jun 7 '18 at 5:37
  • can you please post your collection code – Prashant Valanda Jun 7 '18 at 5:55
  • i have added my collection class below pls check – Ritesh Shukla Jun 7 '18 at 19:29

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.