I'm facing an strange issue in fetching filtered data in admin grid. I had tried to filter the collection using _initSelect function



namespace <vendor>\<module>\Model\ResourceModel\Custom;

use <vendor>\<module>\Model\ResourceModel\AbstractCollection;

class Collection extends AbstractCollection
    protected $_idFieldName = 'event_id';
    protected $_previewFlag;

    protected function _construct()
        $this->_init('<vendor>\<module>\Model\Custom', '<vendor>\<module>\Model\ResourceModel\Custom');
    protected function _initSelect()
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $request = $objectManager->get('Magento\Framework\App\Request\Http');
        $event_id =  1;
        $this->addFieldToFilter("event_entity_id", $event_id);
        return $this;

It's working with static event_id but, not able to fetch when I try it with dynamic event_id via request params.

Let me know If anything is wrong.


1 Answer 1


Fixed it by using mentioned below steps

  1. Store param value in session in the controller

public function execute() { $this->_catalogSession->setTokenId($this->request->getParam('entity_id')); $this->_view->loadLayout(); $this->_view->loadLayoutUpdates(); $this->_view->getPage()->getConfig()->getTitle()->set(__('Redeem Token History')); $this->_view->renderLayout(); }

  1. Use session value in data provider

$tokensCollection->addFieldToFilter('token_id', ['eq' => $this->_catalogSession->getTokenId()]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.