1

In Magento 2.2.5, I have a custom agrid. It has edit option and url parameters.

I need to create another grid in the edit page based on the url parameter. ie., I need to filter the custom grid based on the url parameter.

Note: Am not using ui component to create grid.

Code: https://pastebin.com/z9aww705

Screenshot

1
  • Could you please add your ui component file ? Oct 3 '18 at 6:30
1

Please find below line in your ui component file.

<item name="update_url" xsi:type="url" path="mui/index/render"/>

After that add below code after that line.

<item name="filter_url_params" xsi:type="array"> 
     <item name="id" xsi:type="boolean">1</item>
 </item>

You can get filter data in your grid.

Still you have any query let me know.

8
0

Reference: Marius answer

In the layout xml file, change the Core Grid block to Custom Grid Block like below:

<block class="Magento\Backend\Block\Widget\Grid" name="apptha_merchant_post_grid.grid" as="grid">

Change this to:

<block class="Apptha\Customergroup\Block\Adminhtml\Response" name="apptha_merchant_post_grid.grid" as="grid">

Code of the Block File is:

<?php
namespace Apptha\Customergroup\Block\Adminhtml;
class Response extends \Magento\Backend\Block\Widget\Grid
{    
public function _construct()
{
parent::_construct();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $referenceId = $objectManager->create('Apptha\Customergroup\Model\Deal')
->load($this->getRequest()->getParam('id'))->getData("reference_id");
//We'll get the Grid collection here by using this: $this->getCollection()
//We can filter it like addFieldToFilter method
//Here I am filtering grid collection using reference id
$this->getCollection()->addFieldToFilter('reference_id', array('eq' => $referenceId));
}
}

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.