cancel
Showing results for 
Search instead for 
Did you mean: 

Admin Grid - filter for dynamic param

Admin Grid - filter for dynamic param

Hi,

I want understand the Admin Grid in MAgento 2.

 

EXAMPLE:

This is the gridview of Pages (Content => Pages)

cms - page.png

I want see only one row (random choose between ID 1 - 8). Then I put code for random choose in Controller (method execute):

 

 

/vendor/magento/module-cms/Controller/Adminhtml/Page/Index.php

 

 

/**
* Index action
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{

/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Magento_Cms::cms_page');
$resultPage->addBreadcrumb(__('CMS'), __('CMS'));
$resultPage->addBreadcrumb(__('Manage Pages'), __('Manage Pages'));
$resultPage->getConfig()->getTitle()->prepend(__('Pages'));

//TODO RANDOM CHOOSE id 1 - 8

$dataPersistor = $this->_objectManager->get(\Magento\Framework\App\Request\DataPersistorInterface::class);
$dataPersistor->clear('cms_page');

return $resultPage;
}

 

Then in Collection I want find ID random choose in the controller:

 

 

vendor/magento/module-cms/Model/ResourceModel/Page/Collection.php 

 

/**
     * Perform operations before rendering filters
     *
     * @return void
     */
    protected function _renderFiltersBefore()
    {
        $entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
        $this->joinStoreRelationTable('cms_page_store', $entityMetadata->getLinkField());
    }


How can I do it?


I have an admin grid similar at grid of CMS pages, and I have to call it through another controller by passing a dynamic ID...